I am trying to fetch customer addresses on a custom page using below code.

$addressObject = Mage::getModel('customer/address');
$shipAddress = $addressObject->load($shipId);
$billAddress = $addressObject->load($billId);

But I don't know why I am getting only the billing address data in $shipAddress and $billAddress.
Actually I am getting the address which is lower in the order. For example if modify the code like below

$billAddress = $addressObject->load($billId);
$shipAddress = $addressObject->load($shipId);

Now I am getting the shipping address in both the variables.
Please let me know what is the issue here and how this can be fixed.

1 Answer 1


You have a misconception in how Magento models work.

They are not "loaders" which just give you back a data object.

They represent the entity itself and load themselves (this is called "Active Record").

So you have a model $addressObject and load it twice, from different ids. The second load overwrites the data from the first load.

Your code only works because load() happens to return $this for convenience. In the end $billAddress, $shipAddress and $addressObject all hold the identical object. Objects in PHP are not copied when you assign them to a different variable, the variable only holds a reference to the actual object.

Correct code:

$shipAddress = Mage::getModel('customer/address')->load($shipId);
$billAddress = Mage::getModel('customer/address')->load($billId);
  • I have already the code you have mentioned, but it is also not working. Aug 24, 2016 at 6:52
  • Sorry for the previous comment, you are right and the code is working. I am using the same code. Aug 24, 2016 at 6:59

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.