按ID,Magento加载客户地址

时间:2012-11-28 18:16:56

标签: magento

有没有办法通过ID加载客户的地址?

与用户名加载客户的方式相同:

 $customer->loadByEmail($customerEmail);

我需要它,因为我想知道地址是否已经存在,所以我可以决定创建一个新地址或更新现有地址

3 个答案:

答案 0 :(得分:20)

我使用它,因为他们可以在Mage中设置多个地址......

$customer = Mage::getModel('customer/customer')
    ->load($customer_id); // insert customer ID

foreach ($customer->getAddresses() as $address)
{
    $data = $address->toArray();
    var_dump($data);
}

当然var_dump将显示所有数组数据..由此来操作并提取您正在寻找的地址。

答案 1 :(得分:17)

假设'ID'指的是地址id(而不是客户ID),那么

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

(通过id加载时进行安全检查总是明智的)

请参阅app / code / core / Mage / Customer / controllers / AddressController.php中的deleteAction()

答案 2 :(得分:1)

尝试以下方法:

#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;