我建立了一个观察者,newsletter_subscriber_save_before event;
当客户订阅/取消订阅时事通讯时,它会被触发。我需要相应地更改此客户 groupID。看来我可以更改 GroupId,但我无法保存它。如果我在我的代码中调用$customer->save()
- 方法,我会陷入无限循环;如果我尝试加入newsletter_subscriber_save_after
事件,也会发生同样的情况。
任何人都可以帮助我吗?将不胜感激!
这是我在 Observer.php 中的代码:
public function newsletter_subscriber_change($observer) {
try {
// get status of subscriber
$subscriber = $observer->getEvent()->getSubscriber();
$status = $subscriber->getStatus();
$email = $subscriber->getEmail();
$customer = Mage::getSingleton('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);
// here i change the groupId
$customer->setData( 'group_id', 9 );
// if i check the group here, the change applied ...
$customer_group = $customer->getGroupId();
// i tried saving with following, but run into loop
$customer->save();
} catch (Exception $e) {
Mage::log("newsletter_subscriber_change observer failed: " . $e->getMessage());
}
}