Magento rounding tax problem

I had a strange rounding problem for VAT in Magento. My product is customized * product price including 20% ​​VAT 183.59

I added 30 items to the basket and it would cost 30 * 183.59 = 5507.70. I see this value in the basket / check, so it's fine. If I have only 1 item in the cart, everything is fine.

Also the final VAT will be 5507.70 * 20/120 = 917.95, but I get 918.00

Do you have an idea how to fix this or where will I look? Thanks in advance.

+6
source share
2 answers

I finally found a solution. I changed the system> VAT> tax calculation method based on the price from unit to line, and it works, more details here

The problem I found is in the core/store model. I had to rewrite the roundPrice method and change the rounding accuracy there.

 public function roundPrice($price) { return round($price, 4); } 
+8
source

Information

The round price in Magento is based on the previous rounding rounding operation.

application / code / core / Mag / Tax / Model / Sales / Total / Quote / Tax.php : 1392 application / code / core / Mage / Tax / Model / Sales / Total / Quote / Subtotal .php: 719

 protected function _deltaRound($price, $rate, $direction, $type = 'regular') { if ($price) { $rate = (string)$rate; $type = $type . $direction; // initialize the delta to a small number to avoid non-deterministic behavior with rounding of 0.5 $delta = isset($this->_roundingDeltas[$type][$rate]) ? $this->_roundingDeltas[$type][$rate] : 0.000001; $price += $delta; $this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price); $price = $this->_calculator->round($price); } return $price; } 

Sometimes this can cause an error due to a high delta calculation error ( $this->_calculator->round($price) ). For example, for this reason, some prices may vary in the range of Β± 1 cent .

Decision

To avoid this, you need to increase the accuracy of the delta calculation.

Change

 $this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price); 

to

 $this->_roundingDeltas[$type][$rate] = $price - round($price, 4); 

Changes must be made in both files:

application / code / core / Mag / Tax / Model / Sales / Total / Quote / Tax.php : 1392 application / code / core / Mage / Tax / Model / Sales / Total / Quote / Subtotal .php: 719

Do not modify or crack kernel files! Rewrite!

The solution was tested in different versions of Magento 1.9.x, but perhaps this will work in earlier versions.

PS

roundPrice as shown below can solve the rounding error problem, but it can cause others (for example, some platforms require rounding to 2 decimal places).

application / code / kernel /Mage/Core/Model/Store.php: 995

 public function roundPrice($price) { return round($price, 4); } 
+5
source

All Articles