magento save shipping amount in quote

10,242

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.

Share:
10,242
webmaker1
Author by

webmaker1

logic is god

Updated on June 04, 2022

Comments

  • webmaker1
    webmaker1 almost 2 years

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