user3564050
user3564050

Reputation: 138

Magento - get Customer Address id of order shipping address

I got the shipping address of an order by $order->getShippingAddress()

$order = Mage::getModel('Mage_Sales_Model_Order');
$order->loadByIncrementId($ext_order_id);
$address = $order->getShippingAddress();

and i load the DefaultBillingAddress by

$address_default_billing = Mage::getSingleton('customer/session')->getCustomer()
                                    ->getDefaultBillingAddress();

Now i want to compare them, but there's the problem. If i do a getId() on both of them, they have different id's even though i chose the billing address for shipping in checkout, so they have to be the same but the id is different.. how can that appear ? Is there a way to get the customer-address-id of the current shippingaddress in checkout ?

by example: $address->getId() returns 44 and $address_default_billing->getId() return 6

the 6 is the right id for the customer address in the model, but the order-shipping-id is wrong.

Upvotes: 3

Views: 11308

Answers (2)

Amit Bera
Amit Bera

Reputation: 7611

you can get customer address by customer_address_id field in sales_flat_order_address table

here the code:

$order = Mage::getModel('sales/order');
$order->loadByIncrementId($ext_order_id);
$address = $order->getShippingAddress();
$address->getData('customer_address_id');

Upvotes: 3

MagePal Extensions
MagePal Extensions

Reputation: 17656

The address id will never be the same, because after an order is placed the address info will 'never' change while customer address change as customer move or change there shipping address.

Order address is store in sales_flat_order_address

Customer address is store in customer_address_entity*

To compare the address you want want to compare individual elements

$address_data = $address->getData()
$address_default_billing_data = $address_default_billing->getData()

$compare = array('firstname', ..., 'city');

foreach($compare as $c){
   if($address_data[$c] != $address_default_billing_data[$c]){
     //not equal
     break;
   }

}

Upvotes: 0

Related Questions