cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 Customer Save Event

Magento2 Customer Save Event

Hello All,

 

After customer registration i  used customer_register_success event  and adminhtml_customer_save_after now  i want to fetch customer details in my observer. So how can i fetch contact number of a customer in my observer.

 

As for customer registration from frontend contact number is not filled, so we wont be able to get contact number for customer_register_success this event.

 

But when we create customer from admin, i use adminhtml_customer_save_after this event. So here how can we get Contact number in my observer ?

 

Can anyone suggest me.

Magento Developer
Ankita Biswas
2 REPLIES 2

Re: Magento2 Customer Save Event

Without filling the detail from fronend, you are not able to get the data into observer.

here you can do one things, put custom attribute for number into frontend registration process and fetch those value here.

Was my answer helpful? You can Click Kudos/Accept As Solution.
200+ professional extensions for M1 & M2 with free lifetime updates!

Re: Magento2 Customer Save Event

@Ankita Biswas if you check the Magento create account controller code  in "vendor/magento/module-customer/Controller/Account/CreatePost.php" you will observe the customer is passed in the second argument to the dispatch method.

 

 

     $this->_eventManager->dispatch(
                'customer_register_success',
                ['account_controller' => $this, 'customer' => $customer]
            );

 

So in your observer class you can do following to get customer object 

 

$customer = $observer->getCustomer();

 

Suman Kar(suman.jis@gmail.com) Magento Certified Developer Plus Skype: sumanphptech Problem solved? Please give 'Kudos' and accept 'Answer as Solution'.