从观察者设置客户组 ID 时遇到问题。该事件正在通过 customer_register_success 事件创建新用户。该事件被传递给我的观察者,例如
public function registrationSuccess(Varien_Event_Observer $observer) {
// extract customer data from event
$customer = $observer->getCustomer()->getData();
Mage::log('COOKIES', json_encode($_COOKIE));
// a cookie should have been set with the membership id
if (isset($_COOKIE['membership_account_id'])) {
Mage::log('COOKIE SET, ASSOCIATING MEMBERSHIP');
// associate new account with membership, and upgrade user to membership status
$this->associateMembership($customer['entity_id'], $_COOKIE['membership_account_id']);
}
}
然后调用 associateMembership 方法来更新组 ID,并设置一个名为 rms_id的自定义客户属性:
public function associateMembership($customer_id, $account_id) {
// load customer model
$customer = Mage::getModel('customer/customer')->load($customer_id);
Mage::log('CUSTOMER DATA: ' . json_encode($customer->toArray()));
// upgrade customer to membership level, and set custom rms_id attribute
$customer
->setWebsiteId(Mage::app()->getWebsite()->getId())
->setGroupId(4)
->setRmsId($account_id);
// save
try {
$customer->save();
Mage::log('ACCOUNT ASSOCIATED: CUSTOMER ID = ' . $customer_id . ' ACCOUNT ID = ' . $account_id);
} catch (Exception $ex) {
Mage::log($ex);
}
}
由于某种原因,没有错误回来。我得到了正确的用户 ID,一切似乎都在工作。但是,未设置该组,我的自定义 ID 也未设置。
我应该使用另一个允许保存的事件吗?