1

I have created an observer on the customer_save_before event. Surprisingly $observer->getEvent()->getCustomer()->getOrigData() is null. Is my expectation wrong?

This is also happening for customer_save_commit_after.

I am looking for an event for which the customer data (new and original) is available, that ideally takes place after the new data was persisted in the db, independent of the area from which it is called frontend or adminhtml.

I have logged all the events that are being dispatched throughout my save customer process and the two events mentioned above made the most sense.

Is there such an event?

Thanks!

1
  • Radu, have you found a solution? Aug 25, 2022 at 7:09

2 Answers 2

0
$customer->getOrigData()

 return null because it never loaded.

Reference Link

4
  • 3 year old bug. They closed it too. Wow. May 22, 2019 at 21:51
  • so what is the workaround in the case? explicitly call $customer->load ?
    – Radu
    May 23, 2019 at 16:15
  • $observer->getEvent()->getCustomer()->getData(); May 23, 2019 at 18:12
  • this is not changing anything. I was asking if the workaround for getting the origData is to explicitly call $customer->load
    – Radu
    May 23, 2019 at 22:43
0

Did you try one of the suggestions in the magento git issue report? Only reason I ask is because he seems so certain. I'm away from computer at the moment so can't test.

$customerData = $observer->getEvent()->getData('customer');
$newData = $customerData->getData('attriubute_code');
$previousData = $customerData->getOrigData('attribute_code')
1
  • not working. $previousData is null
    – Radu
    May 23, 2019 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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