我在 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;
}
}
}