Php 购物车价格规则-对任何方法应用免费送货
我有一个提供不同运费的扩展,此模块在管理面板中有一个选项,允许您在符合购物车价格规则的情况下选择免费送货方式(如果遵守购物车价格规则要求,则将此方法设置为免费)。Php 购物车价格规则-对任何方法应用免费送货,php,magento,shipping,Php,Magento,Shipping,我有一个提供不同运费的扩展,此模块在管理面板中有一个选项,允许您在符合购物车价格规则的情况下选择免费送货方式(如果遵守购物车价格规则要求,则将此方法设置为免费)。 问题是我只能选择一种方法,但在同一个国家,我提供两个不同的承运人来交付包裹(不同地区的最低价格),这是一个问题。 扩展将值保存在路径下的核心配置数据表中。我不清楚magento如何访问此信息,因此我通过SSH运行了以下命令: grep -rnw 'app' -e "carriers/premiumrate/free_method"
问题是我只能选择一种方法,但在同一个国家,我提供两个不同的承运人来交付包裹(不同地区的最低价格),这是一个问题。
扩展将值保存在
路径下的核心配置数据表中。我不清楚magento如何访问此信息,因此我通过SSH运行了以下命令:
grep -rnw 'app' -e "carriers/premiumrate/free_method"
没有结果,所以我尝试了:
grep -rnw 'app' -e "free_method"
结果:
app/code/core/Mage/Shipping/Helper/Data.php:159: $freeMethod = Mage::getStoreConfig('carriers/' . $arr[0] . '/free_method', $storeId);
app/code/core/Mage/Shipping/Model/Carrier/Abstract.php:56: protected $_freeMethod = 'free_method';
下一次搜索:
grep -rnw 'app' -e "freeMethod"
结果:
app/code/core/Mage/Shipping/Helper/Data.php:159: $freeMethod = Mage::getStoreConfig('carriers/' . $arr[0] . '/free_method', $storeId);
app/code/core/Mage/Shipping/Helper/Data.php:160: return $freeMethod == $arr[1];
app/code/core/Mage/Shipping/Model/Carrier/Abstract.php:343: $freeMethod = $this->getConfigData($this->_freeMethod);
app/code/core/Mage/Shipping/Model/Carrier/Abstract.php:344: if (!$freeMethod) {
app/code/core/Mage/Shipping/Model/Carrier/Abstract.php:351: if ($item->getMethod() == $freeMethod) {
app/code/core/Mage/Shipping/Model/Carrier/Abstract.php:363: $this->_setFreeMethodRequest($freeMethod);
app/code/core/Mage/Shipping/Model/Carrier/Abstract.php:373: && $rate->getMethod() == $freeMethod
因此,我打开了app/code/core/Mage/Shipping/Model/Carrier/Abstract.php
,以下是我感兴趣的行(370
-378
;我在底部添加了完整的函数):
if (count($rates) > 1) {
foreach ($rates as $rate) {
if ($rate instanceof Mage_Shipping_Model_Rate_Result_Method
&& $rate->getMethod() == $freeMethod
) {
$price = $rate->getPrice();
}
}
}
- 这是我必须编辑的正确位置吗
- 如果我删除
if
条件,我会销毁我的站点吗李>
- 如果购物车规则不适用,我应该如何设置任何免费送货
有效/有效
- 有没有更好的方法来找出我必须编辑的内容
而不是随机grep?
完成功能:
protected function _updateFreeMethodQuote($request)
{
if ($request->getFreeMethodWeight() == $request->getPackageWeight() || !$request->hasFreeMethodWeight()) {
return;
}
$freeMethod = $this->getConfigData($this->_freeMethod);
if (!$freeMethod) {
return;
}
$freeRateId = false;
if (is_object($this->_result)) {
foreach ($this->_result->getAllRates() as $i=>$item) {
if ($item->getMethod() == $freeMethod) {
$freeRateId = $i;
break;
}
}
}
if ($freeRateId === false) {
return;
}
$price = null;
if ($request->getFreeMethodWeight() > 0) {
$this->_setFreeMethodRequest($freeMethod);
$result = $this->_getQuotes();
if ($result && ($rates = $result->getAllRates()) && count($rates)>0) {
if ((count($rates) == 1) && ($rates[0] instanceof Mage_Shipping_Model_Rate_Result_Method)) {
$price = $rates[0]->getPrice();
}
if (count($rates) > 1) {
foreach ($rates as $rate) {
if ($rate instanceof Mage_Shipping_Model_Rate_Result_Method
&& $rate->getMethod() == $freeMethod
) {
$price = $rate->getPrice();
}
}
}
}
} else {
/**
* if we can apply free shipping for all order we should force price
* to $0.00 for shipping with out sending second request to carrier
*/
$price = 0;
}
/**
* if we did not get our free shipping method in response we must use its old price
*/
if (!is_null($price)) {
$this->_result->getRateById($freeRateId)->setPrice($price);
}
}