Prestashop getPackageShippingCost() 修改

Prestashop getPackageShippingCost() modification

我正在研究 PRESTASHOP 覆盖选项, 我需要更新 override/classes/Cart.php 中的函数 getPackageShippingCost() 例如,我希望 prestashop 仅在我的 id_carrier 为 5 时才考虑此覆盖,是否可能?

是的,您可以像这样轻松地做到这一点:

class Cart extends CartCore
{

    public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
    {

        if ($id_carrier !== 5)
        {
            return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone);
        }

        // YOUR CUSTOM CODE
    }
}

不要忘记在添加新覆盖后删除文件 /cache/class_index.php