Download customer address by ID, Magento

Is there any way to load the client address by ID?

Similar to how a user loads by username:

$customer->loadByEmail($customerEmail); 

I need this because I'm trying to find out if an address exists, so I can decide to create a new one or update an existing one

+4
source share
3 answers

Assuming "ID" refers to an address identifier (not a client identifier), then

 $id = 5; Mage::getModel('customer/address')->load($id); 

(it is always useful to perform a security check when booting by id)

See deleteAction () in application / code / kernel / Mage / Client / controllers / AddressController.php

+14
source

I use this because they can set more than one address in the Mage ...

 $customer = Mage::getModel('customer/customer') ->load($customer_id); // insert customer ID foreach ($customer->getAddresses() as $address) { $data = $address->toArray(); var_dump($data); } 

Of course, var_dump display all the data in the array .. it's up to you to manipulate and pull out the address you are looking for at the moment.

+18
source

Try the following:

 #customer id here $customerId = 1; #load customer object $customer = Mage::getModel('customer/customer')->load($customerId); //insert cust ID #create customer address array $customerAddress = array(); #loop to create the array foreach ($customer->getAddresses() as $address) { $customerAddress[] = $address->toArray(); } #displaying the array echo '<pre/>';print_r($customerAddress );exit; 
+1
source

All Articles