Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Rule.php
Go to the documentation of this file.
1 <?php
13 
16 
17 abstract class Rule extends \Magento\Backend\App\Action
18 {
24  const ADMIN_RESOURCE = 'Magento_Tax::manage_tax';
25 
31  protected $_coreRegistry = null;
32 
36  protected $ruleService;
37 
42 
49  public function __construct(
50  \Magento\Backend\App\Action\Context $context,
51  \Magento\Framework\Registry $coreRegistry,
52  \Magento\Tax\Api\TaxRuleRepositoryInterface $ruleService,
53  \Magento\Tax\Api\Data\TaxRuleInterfaceFactory $taxRuleDataObjectFactory
54  ) {
55  $this->_coreRegistry = $coreRegistry;
56  $this->ruleService = $ruleService;
57  $this->taxRuleDataObjectFactory = $taxRuleDataObjectFactory;
58  parent::__construct($context);
59  }
60 
66  protected function initResultPage()
67  {
68  $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
69  $resultPage->setActiveMenu('Magento_Tax::sales_tax_rules')
70  ->addBreadcrumb(__('Tax'), __('Tax'))
71  ->addBreadcrumb(__('Tax Rules'), __('Tax Rules'));
72  return $resultPage;
73  }
74 
82  protected function populateTaxRule($postData)
83  {
84  $taxRule = $this->taxRuleDataObjectFactory->create();
85  if (isset($postData['tax_calculation_rule_id'])) {
86  $taxRule->setId($postData['tax_calculation_rule_id']);
87  }
88  if (isset($postData['code'])) {
89  $taxRule->setCode($postData['code']);
90  }
91  if (isset($postData['tax_rate'])) {
92  $taxRule->setTaxRateIds($postData['tax_rate']);
93  }
94  if (isset($postData['tax_customer_class'])) {
95  $taxRule->setCustomerTaxClassIds($postData['tax_customer_class']);
96  }
97  if (isset($postData['tax_product_class'])) {
98  $taxRule->setProductTaxClassIds($postData['tax_product_class']);
99  }
100  if (isset($postData['priority'])) {
101  $taxRule->setPriority($postData['priority']);
102  }
103  if (isset($postData['calculate_subtotal'])) {
104  $taxRule->setCalculateSubtotal($postData['calculate_subtotal']);
105  }
106  if (isset($postData['position'])) {
107  $taxRule->setPosition($postData['position']);
108  }
109  return $taxRule;
110  }
111 }
__()
Definition: __.php:13
$taxRule
Definition: tax_rule.php:35
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Tax\Api\TaxRuleRepositoryInterface $ruleService, \Magento\Tax\Api\Data\TaxRuleInterfaceFactory $taxRuleDataObjectFactory)
Definition: Rule.php:49