4

I'm using Magento 2 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 has a simple/short solution for this?

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

enter image description here

3 Answers 3

5

This is a workaround for the problem.

Type the following code in console (CTRL + SHIFT + J in Google Chrome). It will trigger clicks for all labels, so that magento's code will mark the tax codes as checked. However the ones which are already checked will get unchecked.

require(["jquery"],function($){
    $(".mselect-fixed label").trigger('click');
});

Try this code if you want to check/click on all the rules which are not already checked:

require(["jquery"],function($){
    $( ".mselect-fixed label" ).each(function( index ) {
  if($(this).children("input").hasClass("mselect-checked")){}
  else $(this).trigger('click');
    });
});
2
  • 2
    I used the above code (as per th3pirat3), but you must scroll first through all options before you can make the selection and apply it to all.
    – Isaac
    Dec 13, 2019 at 1:42
  • This is a ton of time saved!
    – Mike
    May 12, 2021 at 18:31
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.

0

The first answer is perfect with a slight edit, that code will grab ALL of the select lists on the tax class page including the product tax classes below the tax rates at the top, which may not be what the OP wanted.

To get ONLY the tax rates at the top

require(["jquery"],function($){
    $( ".field-tax_rate .mselect-fixed label" ).each(function( index ) {
  if($(this).children("input").hasClass("mselect-checked")){}
  else $(this).trigger('click');
    });
});

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.