Round price after tax application
-
29-09-2020 - |
Question
In my store, CE 1.9.2.2, I would like to round prices after tax application. Example: I have a product with a price 160.50 without taxes applied. For some customers the store applies a tax rule which increases the price of its 22%. So, after the tax calculation, the price for that particular product becomes 195.81. For those customers I would like to have the product priced 196.00 while leaving 160.50 for customers which do not have the tax calculation applied.
Is it possible to achieve this in some way in Magento?
Solution
I managed to do it. This is how I achieved it.
I had to extend the Mage_Tax_Model_Calculation
class and rewrite the logic in the calcTaxAmount
method.
public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
$taxRate = $taxRate / 100;
if ($priceIncludeTax) {
$amount = $price * (1 - 1 / (1 + $taxRate));
} else {
$amount = $price * $taxRate;
}
$taxedPrice = $price + $amount;
$amount += round($taxedPrice) - $taxedPrice;
if ($round) {
return $this->round($amount);
}
return $amount;
}
I just added the two lines:
$taxedPrice = $price + $amount;
$amount += round($taxedPrice) - $taxedPrice;
to sum to the tax amount the difference between taxed price and the rounded taxed price.