按ID Magento加载客户地址

按ID Magento加载客户地址,magento,Magento,有没有办法通过ID加载客户地址 与按用户名加载客户的方式类似: $customer->loadByEmail($customerEmail); 我需要它,因为我试图知道地址是否已经存在,以便我可以决定创建一个新地址或更新现有地址。我使用它,因为他们可以在Mage中设置多个地址 $customer=Mage::getModel('customer/customer') ->加载($customer_id);//插入客户ID foreach($customer->getAddresses(

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

与按用户名加载客户的方式类似:

 $customer->loadByEmail($customerEmail);

我需要它,因为我试图知道地址是否已经存在,以便我可以决定创建一个新地址或更新现有地址。我使用它,因为他们可以在Mage中设置多个地址

$customer=Mage::getModel('customer/customer')
->加载($customer_id);//插入客户ID
foreach($customer->getAddresses()作为$address)
{
$data=$address->toArray();
var_dump($数据);
}

当然,
var\u dump
将显示所有数组数据。。此时,由您操作并提取您正在查找的地址。

假设“ID”指的是地址ID(而不是客户ID),则

(按id加载时最好进行安全检查)

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

尝试以下操作:

#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;
#此处为客户id
$customerId=1;
#加载客户对象
$customer=Mage::getModel('customer/customer')->load($customerId)//插入客户ID
#创建客户地址数组
$customerAddress=array();
#循环以创建数组
foreach($customer->getAddresses()作为$address)
{
$customerAddress[]=$address->toArray();
}
#显示阵列
回声';打印地址($customerAddress);出口

哪个地址和上下文?
#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;