【问题标题】:Magento tax rounding issueMagento 税收四舍五入问题
【发布时间】:2012-11-11 20:21:06
【问题描述】:

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

我在购物篮中添加了 30 件商品,费用为 30 * 183.59 = 5507.70。我可以在购物篮/结帐中看到这个值,这很好。如果我的购物篮里只有 1 件商品,那没关系。

最终增值税也是 5507.70 * 20 / 120 = 917.95,但我得到的是 918.00

您知道如何解决此问题或我该去哪里看看吗?提前致谢。

【问题讨论】:

    标签: magento magento-1.9


    【解决方案1】:

    最后我找到了解决方案。我将 System > VAT > Tax Calculation Method Based on 从 Unit price 更改为 Row Total 并且它有效,更多详细信息here

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

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

    【讨论】:

    • 重写绝对不是一个合适的解决方案!对您有好处,但它会导致 PayPal 付款出现问题(有效订单返回标记为“疑似欺诈”)。使用此重写时要小心!
    • 是的,我同意。更改舍入在一个地方修复了我们的问题,但在另一个地方破坏了它。我认为基本上不可能有一个在所有情况下都能完美运行的解决方案。
    • 我终于设法解决了官方知识库条目的一些问题:magentocommerce.com/knowledge-base/entry/…
    • 购物车中 4 个“修复”小计的精确度,但在某些情况下会打乱净/税计算(净 + 税 = 预期总计 + 0.01)。这也会导致 paypal 错误,因为 API 会抱怨错误的值:'ITEMAMT' + 'TAXAMT' != 'AMT'。
    • 这个问题现在已经修复,1.13.1 Magento EE magentocommerce.com/knowledge-base/entry/…
    【解决方案2】:

    信息

    Magento 中基于先前舍入操作 delta 的舍入价格。

    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;
    }
    

    有时这可能会由于高增量计算错误 ($this->_calculator->round($price)) 而导致错误。例如,出于这个原因,某些价格可能会在 ±1 美分的范围内变化。

    解决方案

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

    改变

    $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 上进行了测试,但可能在早期版本中也可以使用。

    附言

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 2018-04-29
      相关资源
      最近更新 更多