1
ANyone有更新客戶默認運費和帳單地址的示例腳本?我需要循環所有客戶,並在沒有指定國家的情況下將該國設爲默認「美國」。更新默認客戶地址的國家
我試過以下,沒有運氣。有什麼想法嗎?
$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()));
}
}
}
}