1

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

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();
  • thanks!, is there a way to add another code to be included in the quote – pzirkind Sep 17 '14 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

  • +1 for adding a few events plus code (accepted the other answer since it was simpler) – pzirkind Sep 17 '14 at 15:09
  • @Amit this event is not calling, Whenever I am changing the address data like postcode, country, region. – Himanshu Oct 22 '18 at 13:37
  • What event used for getting shipping methods before place an order? – zus Aug 16 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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