I am using CE configured for multi website.

I am trying to resolve an error in a shipping module which restricts certain pincodes.

The module works fine on frontend side but unfortunately it fails if order is created from the admin panel or if I try to add comments to an order.

After bit of debugging I found out that the observer fails to get the postcode from shipping address.




public function Shippingzip(Varien_Event_Observer $observer)
            $collection = Mage::getModel('shippingrestriction/shippingzip')->getCollection();

            $data = array();
            foreach ($collection as $value)
                $data[] = $value->zipcode;
            $address = Mage::getSingleton('checkout/session')->getQuote()

            if (in_array($address->getData('postcode'),$data))
                throw new Mage_Core_Exception(
                Mage::helper('catalog')->__('Shipping is not available for your location.')


While debugging I found out that the below function returns empty value in the admin panel create order page and thus the postcode comparison code in the observer file fails in the admin panel.

$address =  Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();

1 Answer 1


In your observer, instead of

$address = Mage::getSingleton('checkout/session')->getQuote()


$address = $observer->getEvent()->getOrder()
  • Hi, First of all thank you for replying. It worked without any problem. Was it because of ('checkout/session')?
    – danish
    Commented Mar 1, 2016 at 8:55
  • yes :D... checkout session is gone in admin area and you need to take the shipping information from another source. Commented Mar 1, 2016 at 17:24
  • Ok. I am basically a newbie to magento and I don't seem to find much docs about magento functions, events or models or anything. Is there something you can suggest me?
    – danish
    Commented Mar 2, 2016 at 5:57

Your Answer

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

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