我想根据邮政编码和重量确定运费价格magento?

时间:2013-09-12 10:35:19

标签: php magento

我必须根据邮政编码和重量确定magento的运费价格,例如特定邮政编码的运费价格稳定高达20公斤如果退出20公斤我必须增加运费价格每公斤1.30欧元能做到吗?我已经看过桌面费率,但我认为它适合我的情况。任何人都可以帮助我。谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用以下功能:

function calculateShippingFee($parcelWeight, $standardShippingFee){
    $maxWeight     = 20;    //Max weight of parcel before additional cost
    $overWeightFee = 1.30;  //Fee per kg over weight
    $additionalFee = 0; //Initialise additional fee

    if($parcelWeight > $maxWeight){
        $amountOver    = ceil($parcelWeight) - $maxWeight; //Amount over the max weight
        $additionalFee = $amountOver * $overWeightFee; //Additional fee to be charged
    }
    return $standardShippingFee + $additionalFee;
}

将返回计算的运费。您只需为邮政编码提供$parcelWeight$standardShippingFee,例如:

$shippingFee = calculateShippingFee(25, 5.30); //Weight == 25kg, Fee == €5.30

示例输出:

echo calculateShippingFee(19, 10);   // Outputs: 10
echo calculateShippingFee(20, 10);   // Outputs: 10
echo calculateShippingFee(25, 10);   // Outputs: 16.5
echo calculateShippingFee(24.3, 10); // Outputs: 16.5

改变超重费用的功能

function calculateShippingFee($parcelWeight, $standardShippingFee, $overWeightFee){
    $maxWeight     = 20;    //Max weight of parcel before additional cost

    $additionalFee = 0; //Initialise additional fee

    if($parcelWeight > $maxWeight){
        $amountOver    = ceil($parcelWeight) - $maxWeight; //Amount over the max weight
        $additionalFee = $amountOver * $overWeightFee; //Additional fee to be charged
    }
    return $standardShippingFee + $additionalFee;
}