2012-11-23 69 views
5

我在Magento中遇到了一个奇怪的四舍五入问题。我的产品设置为 *产品价格含20%增值税为183.59Magento税收四舍五入问题

我在购物篮中添加了30件商品,价格为30 * 183.59 = 5507.70。我可以在购物篮/结帐中看到这个值,所以没关系。如果我在篮子里只有一件物品,那就没问题。

而且最终的增值税将是5507.70 *一百二十零分之二十〇= 917.95,但我越来越918.00

你有任何想法如何解决这个问题或者我会看看?提前致谢。

回答

8

最后我找到了解决方案。我改变了系统>增值税>税收计算方法基于从单价到行总计,它的工作,更多细节here

我发现的问题是在core/store模型。我不得不重写roundPrice方法并改变那里的舍入精度。

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

重写绝对不是一个合适的解决方案!对你有好处,但它会导致PayPal支付问题(有效订单退货标记为“可疑欺诈”)。当你使用这个重写时要小心! – simonthesorcerer

+0

是的,我同意。改变四舍五入将我们的​​问题固定在一个地方,但在另一个地方打破了它。我认为在所有情况下都有完美的解决方案基本上是不可能的。 – Jaro

+1

我终于成功解决了一些与te官方知识库条目有关的问题:http://www.magentocommerce.com/knowledge-base/entry/magento-ce-18-ee-113-tax-calc – simonthesorcerer

4

信息

一轮的价格在Magento根据以往的整操作三角洲。

app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php:1392 app/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; 
} 

有时,这可以导致错误由于高delta计算误差($this->_calculator->round($price))。例如,由于这个原因,一些价格可以在±1分的范围内变化

解决方案

要避免这种情况,您需要提高增量计算的准确性。

变化

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

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

的变化需要在这两个文件来进行:

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

请勿修改或破解核心文件!重写!

该解决方案在不同版本的Magento 1.9.x上进行了测试,但也许这可以在早期版本中使用。

P.S.

更改roundPrice函数,如下所示,可以解决舍入误差问题,但可能会导致其他问题(例如,某些平台需要四舍五入至小数点后两位)。

app/code/core/Mage/Core/Model/Store.php:995

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