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()));
    }

}
4

1 回答 1

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;
于 2013-03-06T06:56:51.623 回答