Magento 2 version 2.2.2
Steps to set tax rules:
Create a configurable product, which has two simple (child) products.
Configurable product is set as taxable with 20% tax setup.
First simple product is set as taxable with 20% tax setup.
Second simple product is set as no tax i.e. 0% tax.
Add second product through configurable options to cart.
Actual result:
Tax of 20% is being applied in cart for the second simple product.
Expected result:
0% tax should be applied for the second simple product.
How can I modify this to achieve my requirement?
Best Answer
I was having the same issue due to UK VAT rules and found several magento bug created on github but no actual fix.
So then while looking for a workaround I have built a module to change the Magento behaviour according to our requirement.
Basically we need to update the definition of
mapItem
method of classMagento\Tax\Model\Sales\Total\Quote\CommonTaxCollector
For that we need to override 2 magento classes i.e. write preference in di.xml
Now in
mapItem
method of classVendorName\MagentoChildProductTaxExtend\Preference\Tax\Model\Sales\Total\Quote\CommonTaxCollector
in line 211, we need to replace the$item->getProduct()->getTaxClassId()
with the child product tax class id.For that, we can change to these lines of code in our own class -
Create your own module and add those codes, this works in every tax related section in magento, Tested on Ver 2.2.2
Cheers!!