Tejas Shah
Tejas Shah

Reputation: 563

How to recalculate tax on new row total in magento?

I’m making a call to $item->calcRowTotal() on a Mage_Sales_Model_Quote_Item object.

This works great to reset the row total and base row total, but it does not affect the row total including tax (row_total_incl_tax) attribute on the item.

I assume I have to manually do this after I have the new row total but I can’t figure out how to properly calculate the tax and populate the row_total_incl_tax attribute on the item.

Any suggestions would be much appreciated.

Upvotes: 0

Views: 2654

Answers (1)

Krishna Sunuwar
Krishna Sunuwar

Reputation: 2945

Get the tax rate and recalculate row_total_incl_tax. Here's how you can get tax rate.

Assuming your order no. is 101.

$sale = Mage::getModel('sales/sale)->load(101)
$taxModel = Mage::getModel('sales/order_tax')
        ->load($sale->getId(), 'order_id');
$taxRate = $taxModel->getPercent()

I think you know how to calculate the tax amount based on row total value.

Edit:

Get tax based on product:

$product = Mage::getModel('catalog/product')->load($item-getProductId());
$request = Mage::getSingleton('tax/calculation')
                    ->getRateRequest()
                    ->setProductClassId($product->getTaxClassId());

$taxRate = Mage::getSingleton('tax/calculation')
                ->getRate($request);

So you know the tax rate, row_total_incl_tax is sum of tax * qty + total amount (or you can calculate anyway you want). May be you need to check if item price is included tax or not, you can do this by Mage::getModel('Tax/Config')->priceIncludesTax()

Upvotes: 1

Related Questions