1

I need to detect a change of qty in product (backoffice change after edit is enough for me). I was trying to do it with simple observer

<event name="cataloginventory_stock_item_save_after">
    <observer name="after_stockitem" instance="Company\Module\Observer\StockitemObserver" />
</event>

And in observer: $item=$observer->getEvent()->getItem();

        if($item->getData('qty')!=$item->getOrigData('qty')) {
           // $this->helper->saveProductToUpdate($item->getProductId());
        }

But the problem is that stockItem (not like product or order) has origData empty. How else can i detect the change?

1

Potentially a magento bug. In my magento 2 travels I've come across this bug.

https://github.com/magento/magento2/issues/4662

Different entity and event but to me reads like exactly the same scenario. Magento team have said it's fixed but it's not and that says to me there is an architecture issue. Although this part is purely speculation.

I can only recommend using a before save and an after save event and having a mechanism to log before and after and work out the difference.

  • Yes, looks like that's the same issue. Seems like origData works for products only. Can't really use save before and after as i need it to be very lite product flagging, that won't be noticeable. With this solution, saving and comparing it will slow it down too much. – Jakub Ilczuk Jun 2 at 19:41
  • Yep i agree not great solution. I can't think of anything else. – Dominic Xigen Jun 2 at 21:11

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.