Set at custom tax class for a quote item
Question
I'm developing av B2B shop, where prices/discounts are fetched from an API when adding to basket. This is done by overriding Mage_Sales_Model_Quote_Item::calcRowTotal
.
Now, based on a variable returned from the API, a quote item price may or may not include tax (25%).
Is there any way to apply a tax on a quote item when adding to basket, even when the product itself does not have a tax class in Magento?
I hope this was properly explained. Many thanks!
Solution
use observer sales_quote_collect_totals_before
and in the observers function try to set the tax to the product depending on the condtions using setTaxClassId
to the product object
public function newTax($observer){
$quote = $observer->getQuote();
foreach ($quote->getAllItems() as $quoteItem)
{
$product = $quoteItem->getProduct();
// here you can assign tax to the product depending on your conditions
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange