Magento - customer_save_after always fired twice

前端 未结 5 1736
旧时难觅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:58

    Be careful with Jonathans solution, 'customer_save_observer_executed' stays in the session, so event will not be fired again in the browser session. So it's generally a bad idea, because it will not allow to register two or more customers in a row(actually, it will, but events will not be fired)

    I suggest the following solution:

    public function customerRegister(Varien_Event_Observer $observer)
    {       
        $customer = $observer->getEvent()->getCustomer();          
        if (!$customer->getId())
            return $this;                
    
        if(Mage::registry('customer_save_observer_executed_'.$customer->getId()))
            return $this;  
    
        //your code goes here
    
        Mage::register('customer_save_observer_executed_'.$customer->getId(),true); 
    }  
    

提交回复
热议问题