I have events that I wish to execute when a customer registers or saves their details. For this, I am using two events: customer_register_success and customer_save_after. The problem I am having is that I end up running the task twice as customer_save_after is always called in the same execution as customer_register_success
.
I have tried to detect whether the customer is new by checking the original data and called isObjectNew
, but both return data that implies the object is in fact not new. How can I check to see if the customer is just registering in the customer_save_after event short of setting something in the registry in the customer_register_success
event?
Best Answer
First of all you can define your observer as singleton for both events
In this case the same observer object will be used for both events. So you can create flag in your observer and before doing some actions check it.
Now your code will be executed only once.