customer_save_before
event$customer = $observer->getEvent()->getCustomer();
$customer->getOrigData()
should return data before save, so that we can compare with updated data to perform some logic.
$customer->getOrigData()
return null because it never loaded.
Currently I have to work-around by load customer again in observer.
@hiephm
Please, provide the used version. If the problem is actual for a specific tag, please, specify it and be sure that the latest update was used.
According to contributor guide, tickets without response for two weeks should be closed.
Please feel free to reopen if it's needed.
@palamar I am having the exact same issue as hiephm, I think it has something to do with the fact that the customer admin controller uses the customer repository to load a customer. Because if I reload the entire customer in the observer via the customer model it contains the OrigData.
We are running on Magento 2.1.0 and are using the same event customer_save_after as hiephm.
Same issue here as well. Is there a workaround to check if data was saved on a customer ?
As previously mentioned in the observer the OrigData is null... can't use the dataHasChangedFor on the customer object
@experius-nl have you managed to find a workaround for this? I am having this issue on the frontend as well. Tried a workaround with aroundSave plugin on the resourceModel but same issue.... origData is empty there as wel..
@ksz2013: you need to load customer explicitly in customer_save_before event handler.
That's possible, but it is an additional overload, what is the purpose of the origData if it is not containing the proper values?
Could you please clarify do you save a new customer or an existent one?
@slavvka it's existent customer, that why I expected $customer->getOrigData()
should return original data. This behavior (likely a bug) is simply because customer is never loaded.
The problem must be fixed on the latest mainline. Could you please check that? Soon it will be backported to 2.0 and 2.1
According to contributor guide, tickets without response for two weeks should be closed.
If this issue still reproducible please feel free to create the new one: format new issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result and specify Magento version.
This still hasn't been resolved in 2.1.1
This still happen in 2.1.5 :(
Still happens in 2.1.7
This is fixed on 2.1.2, in your observer:
$customerData = $observer->getEvent()->getData('customer');
$newData = $customerData->getData('xxx_data');
$previousData = $customerData->getOrigData('xxx_data');
Issue is still present in 2.1.7 and 2.2 rc
Issue still present in M2.3
Have you planed to fix it ?
Alternatively, if you can use the event after saving the customer. Use the customer_save_after_data_object event. It is defined in module-customer/Model/ResourceModel/CustomerRepository.php on line 274.
The parameters it passes are customer_data_object and orig_customer_data_object.
Thanks @willstorm !!!
Most helpful comment
Issue still present in M2.3