Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 在下拉列表中设置用户国家/地区_Magento - Fatal编程技术网

Magento 在下拉列表中设置用户国家/地区

Magento 在下拉列表中设置用户国家/地区,magento,Magento,我有一项任务,要求我为所有没有为发货/账单地址设置国家/地区(这是以前的客户导入导致的错误)的客户设置国家/地区。国家/地区现在可用于默认帐单/发货地址 然而,在右侧,国家下拉列表没有填充。我一辈子都不知道如何更新这个。是否属于与发货/账单地址无关的其他地址的一部分 截图: 这是我用来批量更新默认国家/地区的代码 $customers = Mage::getResourceModel('customer/customer_collection'); foreach ($customers as

我有一项任务,要求我为所有没有为发货/账单地址设置国家/地区(这是以前的客户导入导致的错误)的客户设置国家/地区。国家/地区现在可用于默认帐单/发货地址

然而,在右侧,国家下拉列表没有填充。我一辈子都不知道如何更新这个。是否属于与发货/账单地址无关的其他地址的一部分

截图:

这是我用来批量更新默认国家/地区的代码

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

}

从您的屏幕截图中,我可以找到您的第一个地址(不是您的默认地址),您没有设置国家,因此无法在右侧找到设置的国家。接下来,您已正确设置默认地址的国家/地区,但您没有单击该地址以检查是否已设置。。。只要点击左边的地址,你就可以在右边找到相同的地址……这是一个幻觉伴侣;-)顺便说一句,在你的代码中做了一些编辑,让我把它作为一个答案发布
    $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;