不同客户群的统一运费?

时间:2015-12-07 12:08:55

标签: magento shipping

是否可以为两个不同的客户群设置两种不同价格的统一运费方式?

用Google搜索,但找不到一个,为什么这不像人们想象的那样容易设置?

1 个答案:

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