Magento免运费购物车规则在折扣后应用

Mil*_*rov 3 magento

我有一个问题,我无法找到解决方案.我有一个购物车规则,为订单小计> 75美元免费送货.但是,如果使用折扣代码,则会再次应用此规则,尽管订单总金额低于75美元.没有税收和其他费用.我想只有花费> 75美元才能免费送货.任何想法如何解决这个问题?提前致谢

Vin*_*nai 6

您是对的,购物车规则仅适用于购物车小计,自由运输承运人模型也是如此.使用小的重写可以改变freeshipping模型的行为.

首先,停用允许免费送货的购物车规则.然后去System > Configuration > Shipping Methods激活免费送货运营商,给它一个75美元的"最低订单金额".

接下来,我们需要添加重写,以便freeshipping模型使用贴现值而不是小计.

使用适当的模块注册文件添加模块My_Shipping.既然你在询问stackoverflow,我会假设你熟悉创建Magento模块.然后My/Shipping/etc/config.xml使用以下重写声明添加该文件:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <global>
        <models>
            <shipping>
                <rewrite>
                    <carrier_freeshipping>My_Shipping_Model_Freeshipping</carrier_freeshipping>
                </rewrite>
            </shipping>
        </models>
    </global>
</config>
Run Code Online (Sandbox Code Playgroud)

现在唯一缺少的是重写的运营商模型.以下代码实现了您需要的更改:

class My_Shipping_Model_Freeshipping extends Mage_Shipping_Model_Carrier_Freeshipping
{
    /**
     * Force the original free shipping class to use the discounted package value.
     *
     * The package_value_with_discount value already is in the base currency
     * even if there is no "base" in the property name, no need to convert it.
     *
     * @param Mage_Shipping_Model_Rate_Request $request
     * @return Mage_Shipping_Model_Rate_Result
     */
    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {
        $origBaseSubtotal = $request->getBaseSubtotalInclTax();
        $request->setBaseSubtotalInclTax($request->getPackageValueWithDiscount());
        $result = parent::collectRates($request);
        $request->setBaseSubtotalInclTax($origBaseSubtotal);
        return $result;
    }
}
Run Code Online (Sandbox Code Playgroud)

而已.现在,如果包含折扣的小计超过75美元,则可以使用免费送货方式.否则客户将看不到它.