4

Within an observer running before saving a product change in the admin area, how can I get the price of the product before saving?

Using $observer->getProduct()->getPrice() I have the new price which has not been saved yet, but I don't know how to get the old one.

In this observer I need both prices, old and new one.

6

I'm pretty sure that's the purpose of the getOrigData method so you should be able to do:

$observer->getProduct()->getOrigData('price');

Please test that first, I know depending on the event you're observing, this does not behave as intended.

  • 2
    ....and you are right! 👍 – Luigi T. Feb 21 '17 at 15:00

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.