任何人都有用于更新客户默认送货 + 账单地址的示例脚本?我需要遍历所有客户,并将国家/地区设置为默认的“美国”,以防他们没有指定国家/地区。
我尝试了以下,没有运气。有什么想法吗?
$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()));
}
}
}
}