2013-03-02 8 views
1

Magento (청구 및 배송 주소)에서 고객과 관련된 모든 주소를 삭제하려고합니다. 어떻게 프로그래밍 방식으로이 작업을 수행 할 수 있습니까? 누군가 나를 도울 수 있습니까? 이 코드를 사용하고Magento에서 고객 청구서 수신 주소 정리

:

$customer = Mage::getModel('customer/customer'); 
    $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); 

    $customer->loadByEmail((string) $_REQUEST['email']); 

    $address = Mage::getModel('customer/address'); 

    $address->delete(); 

답변

0

당신이 관계를 삭제하거나 모든 주소를 삭제 하시겠습니까? 주소에 많은 외래 키가 있기 때문에

$col = Mage::getModel('customer/customer')->getCollection() 
foreach($col as $customer) { 
    $address = $customer->getDefaultBillingAddress(); 
    // set attributes 
    $address->save(); 

    $address = $customer->getDefaultShippingAddress(); 
    // set attributes 
    $address->save(); 

} 

관계는, 모든 주소

이 나쁜 생각을 삭제합니다. 그러지 마.

+0

주소를 삭제하고 새로운 배송지 및 청구서 수신 주소를 설정하고 싶습니다. – tinkesh

+0

왜 삭제해야합니까? 로드하고 변경하십시오. –

+0

이것은 내 동기 중 하나입니다. 나는 이것을하고 싶다. 나 좀 도와 줄 수있어? – tinkesh

3

고객 컬렉션에서 고객을로드했다고 가정합니다. 고객 ID를 사용하여 고객 주소를로드하고 하나씩 삭제하려면 아래 코드를 찾으십시오.

if($customer){ 
     /*Load the customer addresses by Customer Id*/ 
     $customerAddressCollection = Mage::getResourceModel('customer/address_collection')->addAttributeToFilter('parent_id',$customer->getId())->getItems(); 
     foreach($customerAddressCollection as $customerAddress){ 
      $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(); 
      } 
     } 
    } 
+0

우수 작품 .. 내 시간을 절약했습니다 :-) +1 – Butterfly

관련 문제