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

时间:2012-07-09 10:53:06

标签: magento

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

3 个答案:

答案 0 :(得分: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>

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

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

多数民众赞成。现在,如果包含折扣的小计超过75美元,则可以使用免费送货方式。否则客户将看不到它。

答案 1 :(得分:1)

不幸的是,我注意到了一个错误。他们根据未折现的价值计算小计。您可以解决此问题的方法是为折扣代码规则设置“停止处理规则”。

答案 2 :(得分:1)

您可以尝试按照课程。这必须重写模型“Mage_SalesRule_Model_Rule_Condition_Address”。这会在管理面板中的销售规则管理中为条件选项添加“折扣小计”选项。

class YourCompany_SalesRule_Model_Rule_Condition_Address extends Mage_SalesRule_Model_Rule_Condition_Address {

/**
 * (non-PHPdoc)
 * @see Mage_SalesRule_Model_Rule_Condition_Address::loadAttributeOptions()
 */
public function loadAttributeOptions()
{
    parent::loadAttributeOptions();

    $attributes = $this->getAttributeOption();

    $attributes['base_subtotal_with_discount'] = Mage::helper('salesrule')->__('Subtotal with discount');

    $this->setAttributeOption($attributes);

    return $this;
}


/**
 * (non-PHPdoc)
 * @see Mage_SalesRule_Model_Rule_Condition_Address::getInputType()
 */
public function getInputType()
{
    if ($this->getAttribute() == 'base_subtotal_with_discount')
        return 'numeric';

    return parent::getInputType();
}


/**
 * Add field "base_subtotal_with_discount" to address.
 * It is need to validate the "base_subtotal_with_discount" attribute
 * 
 * @see Mage_SalesRule_Model_Rule_Condition_Address::validate()
 */
public function validate(Varien_Object $address)
{
    $address->setBaseSubtotalWithDiscount($address->getBaseSubtotal() + $address->getDiscountAmount());

    return parent::validate($address);
}

}

相关问题