Magento - customer_save_after always fired twice

前端 未结 5 1749
旧时难觅i
旧时难觅i 2020-12-08 22:36

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

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 22:55

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

提交回复
热议问题