I am using observer for after customer save with following event customer_save_after_data_object

I am trying to get the customer id in observer with following script,

 public function execute(\Magento\Framework\Event\Observer $observer){
    //Do your stuff here!
    echo "<pre>";
    $event = $observer->getEvent();
    $customer = $event->getCustomer();
    die('Observer Is called!');        

Here i can see die result but am't able to customer data


Because there is no object called customer, if we look into the CustomerRepository Model where the event is dispatched, passed data looks like this

$savedCustomer = $this->get($customer->getEmail(), $customer->getWebsiteId());
        ['customer_data_object' => $savedCustomer, 'orig_customer_data_object' => $customer]
return $savedCustomer;

So, instead of $observer->getCustomer(); you will have to $observer->getCustomerDataObject();.

Also, you can try to do it with classic events like customer_save_before and customer_save_after, where you can do it your way, with $observer->getCustomer();


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.