I need to change the tax rate on quote items in a magento2 checkout process that is entirely done programmatically.
What I've found from various resources here on stackoverflow is that is possible to change the quote item's product tax rate
$item->getProduct()->setTaxClassId(1);
In my quote, however, I have many quote items, but they are the all the same catalog-product, only with differrent options aplied to them. Now, when I set the products tax rate like shown above, the last tax-class-id I set is used for ALL items in the quote.
I need a way to set the tax on the quote item directly. But
$item->setTaxPercent(4)
(e.g.)
has no effect.
Best Answer
That's how you should do it:
Change the file app/code/Vendor/Package/etc/di.xml in your custom package by adding the line
Create the plugin
Now, add the content to the file above: