Magento客户保存事件
问题描述:
我正在使用现有的magento页面。登录的用户可以更改他的个人资料信息(名字,姓氏,电子邮件等),他们可以更改他们的帐单和送货地址。Magento客户保存事件
我需要做的是每当客户更改其基本信息或他们的地址之一时发送通知电子邮件。我创建了两个事件的观察者:
<frontend>
<events>
<customer_save_after>
<observers>
<ext_customer_save_after>
<type>singleton</type>
<class>ext/observer</class>
<method>customerSaveAfter</method>
</ext_customer_save_after>
</observers>
</customer_save_after>
<customer_address_save_after>
<observers>
<ext_customer_save_after>
<type>singleton</type>
<class>ext/observer</class>
<method>customerAddressSaveAfter</method>
</ext_customer_save_after>
</observers>
</customer_address_save_after>
</events>
</frontend>
而在customerSaveAfter我发送一封电子邮件,并在customerAddressSaveAfter我检查当前的ID是一样的defaultbillingaddress或defaultshipping地址并相应地发送通知。这工作正常,直到用户选中“设为默认送货地址”复选框。在这种情况下,我突然收到5封电子邮件:
- 帐单地址已变更
- 送货地址变更
- 送货地址变更
- 帐单地址已变更
- 客户信息变更
所以,这些事件突然被多次触发,并且customer_address_save_after以某种方式触发了customer_save_after事件。有没有办法来防止这个或检查哪个事件触发了另一个事件或类似的事情?或者还有其他方法来处理这个问题吗?
我非常感谢任何提示,非常感谢。
答
我真的不能解决问题,与mage_registry我alawys有一个错误,所以我决定去一个完全不同的方法。
在我的扩展中,我删除了观察者,而是创建了2个新的控制器AccountController和AddressController来覆盖Magentos标准控制器以处理客户和地址保存。
在我的config.xml中添加此:
<frontend>
<routers>
<customer>
<args>
<modules>
<my_ext before="Mage_Customer_AccountController">My_Ext</my_ext>
<my_ext before="Mage_Customer_AddressController">My_Ext</my_ext>
</modules>
</args>
</customer>
</routers>
</frontend>
而且,例如,我的AccountController看起来是这样的:
<?php
require_once Mage::getModuleDir('controllers','Mage_Customer').DS."AccountController.php";
class My_Ext_AccountController extends Mage_Customer_AccountController{
public function editPostAction(){
//I copied the code from the Magento AccountController here and at the proper line I added my own code
}
}
与同为我AddressController。这工作非常好。
感谢您的帮助,每个人。
您正在收到5封邮件,可能是因为 - customer_save_after事件每当客户更改任何数据(包括地址,基本配置文件信息等)时都会触发。而您的第二个customer_address_save_after事件会特别触发地址更改。 – Ranjana
但如果客户编辑地址,我只收到一封电子邮件。只有当复选框被选中时才会触发customer_save_event – Chi
没关系,所以可能这与您的问题有关,可以帮助您http://stackoverflow.com/questions/5838346/magento-customer-save-after-always-fired-两次 – Ranjana