最好的方法是添加您自己的“报价地址总计”,就像在 SalesRule 模块中按 Mage_SalesRule_Model_Quote_Freeshipping
类一样。要复制这一点,您需要创建一个扩展类,Mage_Sales_Model_Quote_Address_Total_Abstract
并在其中创建一个方法,collect()
如下所示:
class Mycompany_Mymod_Model_Sales_Quote_Address_Total_Freeshipping extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
public function collect(Mage_Sales_Model_Quote_Address $address)
{
parent::collect($address);
if(somecondition){
$address->setFreeShipping(true);
}
}
}
然后在您的模块 config.xml 中声明您的自定义“报价地址总计”:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<global>
<sales>
<quote>
<totals>
<customfreeshipping>
<class>mymodname/sales_quote_address_total_freeshipping</class>
<after>freeshipping</after> <!-- this ensures our custom total is placed after Mage_SalesRule_Model_Quote_Freeshipping so we can override "$address->setFreeShipping(0);" -->
</customfreeshipping>
</totals>
</quote>
</sales>
</global>
</config>
这将声明地址对象上的免费送货,该地址对象将通过方法内$request->setFreeShipping($this->getFreeShipping());
的Mage_Sales_Model_Quote_Address
类传递给请求对象requestShippingRates()
,然后可用于任何正在检查的送货模块$request->getFreeShipping()
。
享受 :)