Wednesday, May 21, 2014

How to get all available shipping carrier rate by zip code and country code in Magento

If you have country code and zip code then you can find out the all available shipping carrier rate by following code in magento.


$zipcode = '711101';
$country = 'IN';                    
          
$cart = Mage::getSingleton('checkout/cart');
$address = $cart->getQuote()->getShippingAddress();

$address->setCountryId($country)->setPostcode($zipcode)->setCollectShippingrates(true);
$rates = $address->collectShippingRates()->getGroupedAllShippingRates();

foreach ($rates as $carrier) {
             foreach ($carrier as $rate) {
                            print_r($rate->getData());
               }
 }


2 comments:

  1. where i put this code in magento kindly guide me please

    ReplyDelete
  2. I do agree with all the ideas you have presented in your post. They’re really convincing and will certainly work. Still, the posts are very short for newbies. Could you please extend them a little from next time?..Keep this great work
    magento development company in bangalore 

    ReplyDelete