1

I have catalog_product_save_after observer where I want detect when product became available for sale (Magento 2.2). I'm trying to compare some attributes using this code

$old = $product->getOrigData('status');
$new = $product->getData('status');

Which attribute should I use? I was trying

  • is_in_stock -> this is always empty
  • quantity_and_stock_status -> old value is an array new is integer always with value 1
  • status seems to work, but only after second product save. When I click save product once, new status value is always equal old value. When I click save second time (without changing anything) then status has new value.

How can I check this, maybe this is something connected with stockitem?

1

I've found the solution. There is event cataloginventory_stock_item_save_after which should be used to check stock change.

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.