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

Php 我想根据邮政编码和重量确定magento的运费?,php,magento,Php,Magento,我必须根据邮政编码和重量确定magento的运输价格,例如,特定邮政编码的运输价格稳定在20公斤以内,如果存在20公斤,我必须提高运输价格,如每公斤1.30欧元。如何做到?。我已经看过了价格表,但我认为它不适合我的情况。任何人都可以帮助我。谢谢你可以使用如下功能: function calculateShippingFee($parcelWeight, $standardShippingFee){ $maxWeight = 20; //Max weight of parce

我必须根据邮政编码和重量确定magento的运输价格,例如,特定邮政编码的运输价格稳定在20公斤以内,如果存在20公斤,我必须提高运输价格,如每公斤1.30欧元。如何做到?。我已经看过了价格表,但我认为它不适合我的情况。任何人都可以帮助我。谢谢你可以使用如下功能:

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
功能与改变重量费用


你们有一张20公斤以下的邮政编码/价格表吗?如果不是的话,你是如何得到最初的价格是我有邮政编码/价格表高达20公斤。那如果有20公斤,我怎么确定运费呢?谢谢史蒂文。如果我的hv$overWeightFee是稳定的,它看起来很好,但实际问题是$overWeightFee没有被修复。它将根据邮政编码和它的magento进行更改。如果我尝试这样做,我必须把手伸进magento核心部分,所以请建议我!我可以这样做吗?如果超重费用发生变化,您可以更改功能,将其作为输入,请参阅更新的答案。你能展示一些你目前如何使用magento生成费用的示例代码吗?谢谢你的回复。我这样做是为了把这个函数放在哪里?@MarcoMarsala它是一个独立的函数;理论上,你可以把它放在任何你喜欢的地方,在合理的范围内。放置它的最佳位置取决于您的设置,但是如果您只在结帐页面上需要它,您可以将它添加到页面顶部的页面中。
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;
}