Magento:按重量表费率,编辑计算 [英] Magento: Table Rates by Weight, edit the Calculation

查看:88
本文介绍了Magento:按重量表费率,编辑计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在在线商店中使用按重量计的表费率,但我需要自定义计算方式.

I’m currently using Table Rates by Weight for an online store, but I need to customize how the calculation is done.

目前,邮费是由订单的总重量决定的,但我希望计算得出的结果只是根据购物车中最重的物品确定邮寄的费用.

At the moment, the postage fee is determined by the total weight of orders, but I’d like the calculation to just determine the cost of the post by the heaviest item in the shopping cart.

您知道我该如何覆盖此模块进行的计算吗?援助会让我非常感激.

Do you know how I could override the calculations made by this module? Assistance would make me really grateful.

谢谢.

推荐答案

覆盖用于计算这些汇率Mage_Shipping_Model_Shipping的Magento类.提出费率请求时,将使用Mage_Shipping_Model_Rate_Request对象调用此类的collectRates方法,该对象已预先填充了商品和重量.但是,通过使用重写对该类进行子类化,我们可能会比较棘手,并获得所需的比率.

Override the Magento class used to calculate these rates Mage_Shipping_Model_Shipping. When a rate request is made, this class' collectRates method is called using a Mage_Shipping_Model_Rate_Request object, which has the items and weight pre-populated. However, by subclassing that class with our override, we can be tricksy and get the rate we want.

class MyNamespace_MyModule_Model_Shipping extends Mage_Shipping_Model_Shipping {

    public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
        $maxWeight = 0;
        foreach($request->getAllItems() as $item) {
            $maxWeight = max($maxWeight, $item->getRowWeight());
        }
        $request->setPackageWeight($maxWeight);

        return parent::collectRates($request);
    }
}

请注意,这里我们已将已更改代码的数量降至最低,并且可以低风险彻底删除(甚至可以升级Magento!)模块.

Notice that here we've minimized the amount of changed code and our module can be cleanly removed (and we can even upgrade Magento!) with low risk.

希望有帮助!

谢谢, 乔

这篇关于Magento:按重量表费率,编辑计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆