Is there a way to load a customer's address by ID?
Like the way customer loading by username does:
$customer->loadByEmail($customerEmail);
I need it because I'm trying to know if the address already exists so I can decide to create a new one or to update the existing one
I use this, because they can set more than one address in 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 the var_dump
will display all the array data .. it's up to you to manipulate and pull out the address you're looking for at this point.
Assuming that the 'ID' is referring to the address id (and not the customer id) then
$id = 5;
Mage::getModel('customer/address')->load($id);
(it always wise to do security check when loading by id)
See deleteAction() in app/code/core/Mage/Customer/controllers/AddressController.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With