dongqing5925 2015-09-25 11:48
浏览 19
已采纳

Magento客户保存活动

I'm working on an existing magento page. A logged in user can change his profile informamation (firstname, lastname, email, etc.) and they can change their billing and shipping addresses.

What I need to do is send notification emails whenever a customer changes their basic information or one of their addresses. I created an observer for two events:

<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>

And in customerSaveAfter I send an email and in customerAddressSaveAfter I check if the current ID is the same as the defaultbillingaddress or the defaultshipping address and send the notification accordingly. This is working fine, until the user checks the "Set as Default Shipping Address" checkbox. In this case, I suddenly receive 5 emails:

  • Billing Address changed
  • Shipping Address changed
  • Shipping Address changed
  • Billing address changed
  • customer info changed

So, suddenly the events are fired multiple times and the customer_address_save_after somehow triggers the customer_save_after event. Is there a way to prevent this or to check which event triggered another event or something like this? Or are there other ways to handle this problem?

I'd be really thankful for any hints, thank you very much.

  • 写回答

1条回答 默认 最新

  • doudong2149 2015-09-28 08:46
    关注

    I couldn't really solve the problem, with mage_registry I alawys got an error so I decided to go for a totally different approach.

    In my extension I removed the observers and instead created 2 new Controllers, AccountController and AddressController, to overwrite Magentos Standard Controllers for handling customer and address saving.

    In my config.xml I added this:

    <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>
    

    And, for example, my AccountController looks like this:

    <?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
        }
    }
    

    And the same for my AddressController. This worked really nicely.

    Thanks for your help, everyone.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料