Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
tax_rule.php
Go to the documentation of this file.
1 <?php
9 $customerTaxClass = $objectManager->create(\Magento\Tax\Model\ClassModel::class)->load('Retail Customer', 'class_name');
10 $productTaxClass1 = $objectManager->create(\Magento\Tax\Model\ClassModel::class)->load('Taxable Goods', 'class_name');
11 
13  'tax_country_id' => 'US',
14  'tax_region_id' => '0',
15  'tax_postcode' => '*',
16  'code' => '*',
17  'rate' => '10',
18 ];
19 $rate = $objectManager->create(\Magento\Tax\Model\Calculation\Rate::class)->setData($taxRate)->save();
20 
22 $registry = $objectManager->get(\Magento\Framework\Registry::class);
23 $registry->unregister('_fixture/Magento_Tax_Model_Calculation_Rate');
24 $registry->register('_fixture/Magento_Tax_Model_Calculation_Rate', $rate);
25 
27  'code' => 'Test Rule',
28  'priority' => '0',
29  'position' => '0',
30  'customer_tax_class_ids' => [$customerTaxClass->getId()],
31  'product_tax_class_ids' => [$productTaxClass1->getId()],
32  'tax_rate_ids' => [$rate->getId()],
33 ];
34 
35 $taxRule = $objectManager->create(\Magento\Tax\Model\Calculation\Rule::class)->setData($ruleData)->save();
36 
37 $registry->unregister('_fixture/Magento_Tax_Model_Calculation_Rule');
38 $registry->register('_fixture/Magento_Tax_Model_Calculation_Rule', $taxRule);
$registry
Definition: tax_rule.php:22
$rate
Definition: tax_rule.php:19
$customerTaxClass
Definition: tax_rule.php:9
$taxRule
Definition: tax_rule.php:35
$objectManager
Definition: tax_rule.php:8
$productTaxClass1
Definition: tax_rule.php:10
$ruleData
Definition: tax_rule.php:26
$taxRate
Definition: tax_rule.php:12