customer_save_after
顧客が新しいアカウントを作成したり、自分のアカウントを編集しようとしたときに、(いくつかのカスタム登録フィールドに基づいて) イベントを使用して、顧客のデフォルトの配送先住所を作成または更新しようとしています。
Observer モデル コードの一部を次に示します。
...
$customer = $observer->getEvent()->getCustomer();
if ($customer->getId() && $otherConditionIsValid){
$dataShipping = array(
'firstname' => $someFixedFirstName,
'lastname' => $someFixedLastName,
'street' => array($someFixedStreetLine),
'city' => $someFixedCity,
'region' => $someFixedState,
'region_id' => '',
'postcode' => $someFixedZipcode,
'country_id' => $someFixedCountry,
'telephone' => $someFixedTelephone,
);
$customerAddress = Mage::getModel('customer/address');
if($defaultShippingId = $customer->getDefaultShipping()){ //if customer already has default shipping address
$customerAddress->load($defaultShippingId);
}
$customerAddress->setData($dataShipping)
->setCustomerId($customer->getId())
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
$customer->addAddress($customerAddress); #setting Shipping Address to be added/updated
//When i try to use below commented code, script gets called for infinite times, finally running out of memory
/*try{
$customerAddress->save();
}catch(Exception $e){
Mage::log('Address Save Error::' . $e->getMessage());
}*/
}
...
顧客が新しいアカウントを作成すると、上記のコードは正常に機能します。ただし、顧客がカスタム登録フィールドを編集しようとしても、デフォルトの配送先住所は更新されません。My Account > Account Information
したがって、私の主な関心事は、$customer
オブジェクトまたはcustomer_save_after
イベントを使用する他のコードを使用して配送先住所を更新する方法です。