Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load customer address by ID, Magento

Tags:

magento

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

like image 509
jonathanwiesel Avatar asked Nov 28 '22 00:11

jonathanwiesel


2 Answers

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.

like image 54
Zak Avatar answered Jun 18 '23 01:06

Zak


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

like image 39
Renon Stewart Avatar answered Jun 18 '23 00:06

Renon Stewart