3

I'm trying to collect shipping address from order

$order = Mage::getModel('sales/order')->load($order_id, 'increment_id'); 

.......

 $order_Address= $order->getShippingAddress()->getFormated(true);

but it is printing me

Fatal error: Call to a member function getFormated() on a non-object

but when I calling it like this it prints me object

$order_Address= $order->getShippingAddress()
8

The problem is that $order is not set or it's no object (of type Mage_Sales_Model_Order).

Also order with downloadable products have no shipping address.

Edit:

For the updated questions ... make sure loaded $order is valid. It seems the order you're are trying to load isn't correct.^

Use entity_id

$order = Mage::getModel('sales/order')->load(19);

Use increment_id

$order = Mage::getModel('sales/order')->load(300000024, 'increment_id');

You may add a check first

if ($order->getId()) {
    $order_Address= $order->getShippingAddress()->getFormated(true);
}

or

if ($order->getShippingAddress()) {
   ...
}

or

if ($order->getShippingAddress() instanceof Mage_Sales_Model_Order_Address) {
    ...
}
  • loaded order providing me other data correctly like.... $order_tax = $order->getTaxAmount(); – user2366074 Jul 20 '17 at 10:40
  • Please manually check if there is an shipping address ... error says that getShippingAddress() has not returned an object. – sv3n Jul 20 '17 at 10:45
  • Is a downloadable product ordered? – sv3n Jul 20 '17 at 10:50
  • yes print_r( $order->getShippingAddress()) ; provides huge list of data and it also prints object , if ($order->getId()) { $order_Address= $order->getShippingAddress()->getFormated(true); }... it also showing same error ... products are simple products and three are gift card... – user2366074 Jul 20 '17 at 10:55
  • Whats output for var_dump(get_class($order->getShippingAddress()))? – sv3n Jul 20 '17 at 11:01

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.