2

Please, can someone tell me, how to get list shipping addresses and billing addresses the specific customer by customer id in Magento 1.9?

Thanks.

2
  • is your question solved?
    – Gem
    Jul 17, 2017 at 4:10
  • still not yet, I need all list customer address besides default billing and shipping address
    – mrfizh
    Jul 17, 2017 at 4:19

3 Answers 3

4

Try following way:


$customerId = 2;
$customer = Mage::getModel('customer/customer')->load($customerId);
$defaultBilling  = $customer->getDefaultBilling();
$defaultShipping = $customer->getDefaultShipping();

$allAddress = Mage::getModel('customer/address')->getCollection()->setCustomerFilter($customer);

foreach ($allAddress as $address) {
    if($defaultBilling == $address->getId()) {
        // its customer default billing address
    } else if($defaultShipping == $address->getId()) {
        // its customer default shipping address
    } else {
        // its customer other address that saved
    }
}
1
  • this code more complete than mine, I will accept this as answer. hope next could help someone which have same trouble with me in future. Thank you very much @Sohel Rana
    – mrfizh
    Jul 17, 2017 at 4:55
1
please use the below code:

$customer = Mage::getModel('customer/customer')->load($customerId);
$defaultBilling  = $customer->getDefaultBillingAddress();
$defaultShipping = $customer->getDefaultShippingAddress();
1
  • Thank you very much, but I need all address besides default billing address and default shipping address
    – mrfizh
    Jul 17, 2017 at 4:18
1

I had solved my problem,

this is my code, to get all address based customer id :

$customer_id = 1; //example
$customerdata = Mage::getModel('customer/customer')->load($customer_id);

foreach ($customerdata->getAddresses() as $address)
{
$addr = $address->toArray();
echo $addr['street'];
echo $addr['telephone'];
//....
}

Thank you for all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.