Magento 更新默认客户地址上的国家/地区
有人有更新客户默认发货+账单地址的示例脚本吗?我需要遍历所有客户,如果他们没有指定国家/地区,则将国家/地区设置为默认的“美国” 我尝试了以下方法,但没有成功。有什么想法吗Magento 更新默认客户地址上的国家/地区,magento,Magento,有人有更新客户默认发货+账单地址的示例脚本吗?我需要遍历所有客户,如果他们没有指定国家/地区,则将国家/地区设置为默认的“美国” 我尝试了以下方法,但没有成功。有什么想法吗 $customers = Mage::getResourceModel('customer/customer_collection'); foreach ($customers as $customer) { // customer object $customer = Mage::getModel('c
$customers = Mage::getResourceModel('customer/customer_collection');
foreach ($customers as $customer) {
// customer object
$customer = Mage::getModel('customer/customer')->load($customer->getId());
$address = Mage::getModel('customer/address');
if ($default_shipping_id = $customer->getDefaultShipping()) {
$address->load($default_shipping_id);
} else {
$address
->setCustomerId($customer->getId())
->setIsDefaultShipping('1')
->setSaveInAddressBook('1')
;
$address_arr = $address->getData();
// country
if ( !isset($address_arr['country_id']) ) {
$address->setCountryId('United States');
try {
$address->save();
fwrite(STDOUT, '++ COUNTRY UPDATED FOR ' . $customer->getId() . "\n");
} catch(Exception $e) {
error_log(json_encode($e->getMessage()));
}
}
}
}
这是你代码中的一个输入错误 这条线一定很长
$address->setCountryId('US');
而不是
$address->setCountryId('United States');
您应该使用国家id而不是姓名,因为美国是美国。。因此,使用它并将其设置正确