2013-03-05 3 views
0

배송/청구서 수신 주소로 국가가 설정되지 않은 모든 고객 (이전 고객 가져 오기로 인한 오류 임)을 설정해야하는 작업이 있습니다. 현재 기본 청구/배송 주소로 국가를 사용할 수 있습니다.사용자 국가를 드롭 다운으로 설정

그러나 오른쪽에는 국가 드롭 다운이 채워지지 않습니다. 나는이 삶의 방식으로 이것을 업데이트 할 수 없다. 배송/청구서 수신 주소와 관련이없는 다른 주소의 일부입니까?

스크린 샷 : http://cl.ly/image/2G1s261v2a2V

이 내가 기본 국가를 업데이트 배치에 사용했던 코드입니다. 난 당신이 오른쪽에 설정 한 국가를 찾을 수 있도록 당신이 국가를 설정하지 않은 (기본 주소가 아닌 한) 첫 번째 주소를 찾을 수 있습니다 스크린 샷에서

$customers = Mage::getResourceModel('customer/customer_collection'); 

foreach ($customers as $customer) { 

    // get individual customer 
    $customer = Mage::getModel('customer/customer')->load($customer->getId()); 

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

    $address 
     ->setCustomerId($customer->getId()) 
    ; 

    $address_data = $address->getData(); 

    if (!isset($address_data['country_id']) || $address_data['country_id'] == 'United States') { 
     $address->setCountryId('US'); 
    } 

    try { 
     $address->save(); 
    } catch(Exception $e) { 
     Mage::log(json_encode($e->getMessage())); 
    } 

} 
+0

. 다음으로 기본 국가의 국가를 올바르게 설정했으나 주소가 설정되어 있는지 확인하기 위해 클릭하지 않았습니다. 왼쪽에있는 주소를 클릭하기 만하면 오른쪽에 같은 주소를 가져올 수 있습니다. . 착각 친구 ;-) – Haijerome

+0

코드에서 몇 가지 편집 내용을 답으로 게시하도록하겠습니다. – Haijerome

답변

1
$default_country_id = "US"; 

    /*Loads Customer Collection*/ 
    $customers = Mage::getResourceModel('customer/customer_collection'); 
    foreach($customers as $customer): 
     $customerDetails = Mage::getModel('customer/customer')->load($customer->getId()); 
     /*Loads customer addresses*/ 
     foreach ($customerDetails->getAddresses() as $address): 
     /*If country is not set then it will set the default country to the address*/ 
     if(!$address->getData('country_id')){ 
      $address->setCountryId($default_country_id)->save(); 
     } 
     endforeach; 
    endforeach; 
관련 문제