0

I want to know how to solve this problem:

I need to trigger an observer when a customer is created and one different when customer is updated.

I was using customer_save_before event which works everytime you press Save Customer, the problem with this event is that I don't know if the user is created or updated. I have tried to get the ID of the customer and do something like this:

$customer = $observer->getEvent()->getCustomer();

if($customer->getId() == null){

    $event = $CREATE_ACCOUNT_EVENT;
}
else {
    $event = $UPDATE_ACCOUNT_EVENT;
}

The problem is that it always sends event $UPDATE_ACCOUNT_EVENT; It's like if the ID is created always before accessing to the observer. Is there any other event which just triggers when customer is created? so I can use that one for $CREATE_ACCOUNT_EVENT;

If not how can I check if the ID of the customer exists or not?

Greetings!

2

You can use customer_register_success event for create account event in your custom module.

Also, below is the reference link for all the events list available in Magento 2.

https://www.rakeshjesadiya.com/list-of-all-events-in-magento-2/

Hope it helps!!!

  • But is this event for admin panel? I have used this event just in frontend – Oscar Vazquez Sep 12 '19 at 17:30
  • You can give a try with this event in the admin, I'm not sure its working or not. – Sumit Sep 12 '19 at 17:34
  • 1
    Wow I did not believe that it could work on backend, I just put my events.xml file inside admin html, seems to work. – Oscar Vazquez Sep 12 '19 at 21:09
0

There is not specific event for customer update you can try with below event

adminhtml_customer_prepare_save

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.