1

What event do I need to observe to see what shipping methods are available for a given quote

2 Answers 2

1

You can listen to the "sales_quote_save_after" event, then use the quote to get the shipping rates. The following code can be used to get the list of shipping rates.

$quote->getShippingAddress()->getGroupedAllShippingRates();
1
  • thanks!, is there a way to add another code to be included in the quote
    – pzirkind
    Sep 17, 2014 at 15:07
0

There are lot of event.But i cannot find any proper event.

checkout_cart_save_after
sales_quote_collect_totals_after
sales_quote_collect_totals_after

etc

checkout_cart_save_after and sales_quote_collect_totals_after better because it trigger always whenever you have done any changes.

but you get list of available shipping methods.then we need some code at observer

   $quoteShippingAddress = $quote->getShippingAddress();
        if (!is_null($quoteShippingAddress->getId())) {



        try {
            $quoteShippingAddress->collectShippingRates()->save();
            $groupedRates = $quoteShippingAddress->getGroupedAllShippingRates();

            $ratesResult = array();
            foreach ($groupedRates as $carrierCode => $rates ) {
                $carrierName = $carrierCode;
                if (!is_null(Mage::getStoreConfig('carriers/'.$carrierCode.'/title'))) {
                    $carrierName = Mage::getStoreConfig('carriers/'.$carrierCode.'/title');
                }

                foreach ($rates as $rate) {

                    $ratesResult[] =  $rate;

                }
            }
        } catch (Mage_Core_Exception $e) {
             $e->getMessage();
        }
 }
         $ratesResult; 

Here $result give of shipping method

2
  • @Amit this event is not calling, Whenever I am changing the address data like postcode, country, region.
    – Himanshu
    Oct 22, 2018 at 13:37
  • What event used for getting shipping methods before place an order?
    – zus
    Aug 16, 2019 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.