1

我必须根据邮政编码和重量确定 magento 的运费,例如,如果特定邮政编码的运费稳定在 20 公斤,如果它退出 20 公斤,我必须提高每公斤 1.30 欧元的运费。如何做到这一点?. 我已经看过表格费率,但我认为它不适合我的情况。谁能帮帮我。谢谢

4

1 回答 1

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;
}
于 2013-09-13T11:52:01.843 回答