我有一个问题,我找不到解决办法。我有一个购物车规则,给订单小计>75美元免费送货。但是,如果使用折扣代码,则即使订单的总金额小于75美元,也会再次应用此规则。没有税收和其他费用。我想给一个免费送货,只有当他们花费>75美元。你知道我该怎么解决这个问题吗?提前感谢
发布于 2012-07-11 15:21:34
你是对的,购物车规则只适用于购物车小计,免费送货承运商模型也是如此。通过一个小的重写,可以改变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美元,则可以使用免费送货方式。否则客户将看不到它。
发布于 2012-07-10 03:34:33
不幸的是,这是我注意到的一个bug。他们根据未贴现的价值计算小计。一种绕过此问题的方法是为您的折扣代码规则设置“停止处理规则”。
发布于 2013-05-29 16:21:34
您可以尝试跟随类。这必须重写模型"Mage_SalesRule_Model_Rule_Condition_Address".这会将"Subtotal with discount“选项添加到管理面板中销售规则管理的条件选项中。
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);
}}
https://stackoverflow.com/questions/11393617
复制相似问题