I'm adding some custom logic in the admin when the customer is saved. I've created an observer on the
customer_save_before event. I am using the following code to get the customer:
/** @var \Magento\Customer\Model\Customer $customer */ $customer = $observer->getEvent()->getCustomer();
While I was relying on
$customer->getGroupId() to get the customer group ID for example I noticed some unexpected behaviour. It was returning the wrong value (it was returning id=1 but in the database the id=4).
Looking into the issue, I've noticed the
getStoredData method on the
\Magento\Framework\Model\AbstractModel (which is extended by
\Magento\Customer\Model\Customer) which returns the correct data form the database.
I wonder why getData is not returning the correct data in this case. I see that
\Magento\Framework\Model\AbstractModel::storedData is being updated with the
\Magento\Framework\Model\AbstractModel::updateStoredData on certain events, but I wonder how reliable storedData is.