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()
0

1 Answer 1

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) {
    ...
}
9
  • loaded order providing me other data correctly like.... $order_tax = $order->getTaxAmount(); Jul 20, 2017 at 10:40
  • Please manually check if there is an shipping address ... error says that getShippingAddress() has not returned an object.
    – sv3n
    Jul 20, 2017 at 10:45
  • Is a downloadable product ordered?
    – sv3n
    Jul 20, 2017 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... Jul 20, 2017 at 10:55
  • Whats output for var_dump(get_class($order->getShippingAddress()))?
    – sv3n
    Jul 20, 2017 at 11:01

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.