Php – How to get Shipping/Billing Address ID of an order outside Magento core API

magentoPHP

I want to get a shipping/billing address id from a just complete order out of Magento.

I have tried the following code but it's not worked:

Mage::getModel('sales/order')->load($array_data["order_id"])->getShippingAddressId()

Does someone have any ideas?

Best Answer

The following might help someone looking for a similar solution:

// Get the id of the last order for the current user(session)
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();        

// If an order actually exists
if ($orderId) {

    //Get the order details based on the order id ($orderId)
    $order = Mage::getModel('sales/order')->load($orderId);

    // Get the id of the orders shipping address
    $shippingId = $order->getShippingAddress()->getId();

    // Get shipping address data using the id
    $address = Mage::getModel('sales/order_address')->load($shippingId);

    // Display the shipping address data array on screen
    var_dump($address);

}

Note: Obviously this solution requires the user to have a current session

Good luck.