1

I'm using Magento2 community and created one tax rule. Problem is i have around 4000 tax rate and if i manually selecting tax rates then it takes too much time. So anyone have simple/short solution for this?

Thanks in advance. Please check attached image for tax-rates selection.

enter image description here

0

You can create a one-time script if it is not part of any module and it's a one time work only.

Here is a code which might work for you though it is not tested and may require some work.

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$appState = $objectManager->get('\Magento\Framework\App\State');
$appState->setAreaCode('adminhtml');    

 // logic to update rules
 $rule = $objectManager->create('Magento\Tax\Model\Calculation\Rule')->load(1);
 $rule->setCode("taxable_goods");
 $rule->setPriority(0);
 $rule->setCustomerTaxClassIds([1]);
 $rule->setProductTaxClassIds([1,2]);
 $rule->setTaxRateIds([1,2,3,4,5,6,7]);
 $rule->save();

Note: Use of object manager is not appreciated this code is just to give idea of how the objective can be achieved.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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