2
我想删除在magento后端没有默认的客户地址。我已经使用下面的代码来删除,但它从通讯录中删除所有地址。从客户地址删除地址
<?php
$customer = Mage::getModel('customer/customer')->load(2);
if($customer){
/*Load the customer addresses by Customer Id*/
$customerAddressCollection = Mage::getResourceModel('customer/address_collection')->addAttributeToFilter('parent_id',$customer->getId())->getItems();
echo '<pre>';
foreach($customerAddressCollection as $customerAddress){
var_dump($customerAddress->getData());
$customer_address_id = $customerAddress->getData('entity_id');
if($customer_address_id!=""){
/*Load the Customer Address by ID and delete it*/
Mage::getModel('customer/address')->load($customer_address_id)->delete();
}
}
}
?>
那么如何防止删除默认的账单和送货地址。 请帮助
抱歉,但它不工作 – Zaheerabbas 2014-10-01 10:05:39
编辑,请使用$ customer-> getDefaultBillingAddress(),并且您必须获得此地址集的ID $ def_billing = founded_ID; $ def_shipping = created_ID并将其添加到我的答案中,或者发布到com我会为其他thx芬兰人的答案 – Martin 2014-10-01 10:15:14