是否可以为两个不同的客户群设置两种不同价格的统一运费方式?
用Google搜索,但找不到一个,为什么这不像人们想象的那样容易设置?
答案 0 :(得分:0)
您可以通过在本地代码池core/Mage/Shipping/Model/Carrier/Flatrate.php
中复制Flatrate文件local/Mage/Shipping/Model/Carrier/Flatrate.php
来创建此选项。
您需要修改collectRates
函数中的代码。
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') { // per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') { // per item
$shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
} else {
$shippingPrice = false;
}
使用以下代码替换上面的代码:
if(!Mage::getSingleton('customer/session')->isLoggedIn()){
//not logged in
$flatRatePrice = $this->getConfigData('price');
}else{
// logged in
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$group = Mage::getSingleton('customer/group')->load($groupId)->getData('customer_group_code');
$group = strtolower($group);
switch ($group) {
case 'general': //Set price for different customer group
$flatRatePrice = 10;
break;
case 'retailer':
$flatRatePrice = 20;
break;
case 'wholesale':
$flatRatePrice = 30;
break;
default:
$flatRatePrice = $this->getConfigData('price');
}
}
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') { // per order
$shippingPrice = $flatRatePrice;
} elseif ($this->getConfigData('type') == 'I') { // per item
$shippingPrice = ($request->getPackageQty() * $flatRatePrice) - ($this->getFreeBoxes() * $flatRatePrice);
} else {
$shippingPrice = false;
}