Pregunta

I've added one step after the shipping method in Magento OPC.

I need to double and save the shipping amount if the customer chooses Express shipping. How to achieve this?

What I tried:

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

Which doesn't work.

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;
            }
        }
    }
¿Fue útil?

Solución

As you didn't mention about observer. so you need to create one observer to handle this things

here is very good documentation to achive your goal

just go throw this link and try to understand what they are doing. also if you want to change rate you can also it to your custom code.

hope this will sure help you.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top