What event do I need to observe to see what shipping methods are available for a given quote
2 Answers
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– pzirkindSep 17, 2014 at 15:07
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
-
@Amit this event is not calling, Whenever I am changing the address data like postcode, country, region.– HimanshuOct 22, 2018 at 13:37
-