How to load Total Address collection of customer in magento

16,704

Have you tried doing it this way?

$customer = Mage::getSingleton('customer/session')->getCustomer();
foreach ($customer->getAddresses() as $address) {
    Zend_Debug::dump($address->debug());
}
Share:
16,704
Elamurugan
Author by

Elamurugan

Magento Certified + Web and API Developer with PHPStack, MEAN stack

Updated on June 05, 2022

Comments

  • Elamurugan
    Elamurugan almost 2 years

    I want to load the customer address collection in a custom script.

    This code loads only billing address, but I need to load all the addresses(I have 3 addresses under this customer)

        $customerAddressId =   Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling();
        if ($customerAddressId){
               $address = Mage::getModel('customer/address')->load($customerAddressId);
              // echo "<pre>"; print_r($address->getData());echo "</pre>";
              Zend_Debug::dump($address->debug()); 
              $street = $address->getData('street');
        } 
    

    Tried this but this is not returning the shipping address.

    Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling();
    

    Please help me to load all the addresses from Magento customer table for particular user.

  • Elamurugan
    Elamurugan over 13 years
    getAddressCollection returns array of records with entity_id, dates only. Not address collection , I want to load all the address for the particular user
  • clockworkgeek
    clockworkgeek over 13 years
    My mistake. The method should have been getAddresses()
  • Elamurugan
    Elamurugan over 13 years
    Wow, yes its loading all the addresses. But i dont understand why its loading address array multiple times with in foreach. Even i had only 3.
  • Elamurugan
    Elamurugan over 13 years
    Am sorry its my mistake. Its loading all the addresses correctly. Thanks @clockworkgeek