I have try with this code make tax rule programmatically. but it's not working infact model not loaded. you can see this code :

$objectManagers = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$fixtureTaxRule = $objectManagers->create('Magento\Tax\Model\Calculation\Rule');

i have get this error :

Class 'Magento\TestFramework\Helper\Bootstrap' not found

can you please suggest how can i create tax rule ?

2 Answers 2


Finally i have solve this issue. Now you can use this code and i hope it's also beneficial for you guys.

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $fixtureTaxRule = $objectManager->create(\Magento\Tax\Model\Calculation\Rule::class);
  • Hi, Can you please share your whole code in your answer? Commented Feb 10, 2017 at 11:30

Using object manager is not allowed so answer above seems to be wrong.

Correct answer can be found in setup/src/Magento/Setup/Fixtures/TaxRulesFixture.php in setTaxMode method.

taxRateFactory and taxRateRepository together with taxRuleFactory and taxRuleRepository should be used.

    //Add Tax Rate for selected Tax Mode
    /** @var $taxRate TaxRateInterface */
    $taxRate = $this->taxRateFactory->create();

    $taxRateData = $this->taxRateRepository->save($taxRate);

    //Add Tax Rule for Tax Mode
    /** @var $taxRuleDataObject TaxRuleInterface */
    $taxRuleDataObject = $this->taxRuleFactory->create();


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.