magento在报价中节省运费

时间:2013-09-03 12:01:43

标签: php magento shipping quote

我在Magento OPC中的发货方法后添加了一步。

如果客户选择快递,我需要加倍并保存运费。怎么做到这一点?

我尝试了什么:

1. $quote = $this->getQuote();
 $quote->setShippingAmount($price);
 $quote->setBaseShippingAmount($price);
 $quote->getShippingAddress()->collectShippingRates();
 $quote->getShippingAddress()->collectTotals();
 $quote->save();

哪个不起作用。

2.$address = $this->getQuote()->getShippingAddress();
 $method   = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();

 if ($method) {
    foreach ($address->getAllShippingRates() as $rate) {
         if ($rate->getCode()==$method) {
            $amountPrice = $address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
            $method->setPrice('20');
            $method->setCost('20');
            $shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
            $address->setShippingDescription(trim($shippingDescription, ' -'));
            break;
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

你没有提到观察者。所以你需要创建一个观察者来处理这个事情

这里有非常好的文档来实现你的目标

只需抛出this link并尝试了解他们在做什么。如果你想改变费率,你也可以使用自定义代码。

希望这对您有所帮助。