Sort algorithm: Magento checkout totals sorted wrongly causing wrong shipping tax calculation

前端 未结 6 902
生来不讨喜
生来不讨喜 2020-12-07 15:33

In Magento there is a functionality where you can define the order of total calculation by specifing before and after which totals a total should be run.

I added a c

6条回答
  •  轮回少年
    2020-12-07 16:15

    EDIT: This answer is wrong. See the discussion in the comments.


    As Vinai noted, the problem is that the order function returns 0 even if the parameters are not equal. I modified the function to fall back on the string order of the keys as follows:

    protected function _compareTotals($a, $b)
    {
        $aCode = $a['_code'];
        $bCode = $b['_code'];
        if (in_array($aCode, $b['after']) || in_array($bCode, $a['before'])) {
            $res = -1;
        } elseif (in_array($bCode, $a['after']) || in_array($aCode, $b['before'])) {
            $res = 1;
        } else {
            $res = strcmp($aCode, $bCode); // was $res = 0 before
        }
        return $res;
    }
    

提交回复
热议问题