Magento - customer_save_after总是发射两次 [英] Magento - customer_save_after always fired twice

查看:181
本文介绍了Magento - customer_save_after总是发射两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在magento中使用 customer_save_after 事件,除了1个烦人的事情之外,所有的工作都很好,总是被打开两次。

I am using the customer_save_after event in magento, and all is working fine apart from 1 annoying thing - it is always fired twice.

没有其他模块重写,我找不到其他原因造成这种情况。当我查看所有的事件在这个时候被解雇,这个事件肯定会被解雇两次。

There are no other modules rewriting this and I can find no other reason for this happening. When I look through all of the events getting fired at this time and this event is definately getting fired twice.

有人解释这个吗?

我正在编写一个挂钩的网络服务,其结果是复制的效率非常低。

I am writing a web service that hooks into this and its turning out to be quite inefficient to duplicate things.

推荐答案

我也注意到这种双重保存的行为。阻止与观察者发生问题的方法是在请求中设置一个可以被检查的标志。

I've noticed this double-save behaviour too. The way to prevent issue with your observer is to set a flag in the request that can be checked e.g.

    if(Mage::registry('customer_save_observer_executed')){
        return $this; //this method has already been executed once in this request (see comment below)
    }

    ...execute arbitrary code here....

    /* Customer Addresses seem to call the before_save event twice, 
    * so we need to set a variable so we only process it once, otherwise we get duplicates
    */
    Mage::register('customer_save_observer_executed',true); 

这篇关于Magento - customer_save_after总是发射两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆