1

I need to trigger the inventory changes in Magento 2.0 I have an observer cataloginventory_stock_item_save_commit_after in Magento 1.9 and its working fine.

But I can't find the same observer in Magento 2 (or) is there any other method for triggering inventory changes in Magento-2 ?

1 Answer 1

2

In Magento 2 basically it happens Dynamically with afterSave() method

public function afterSave()
{
    $this->cleanModelCache();
    $this->_eventManager->dispatch('model_save_after', ['object' => $this]);
    $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
    $this->_eventManager->dispatch($this->_eventPrefix . '_save_after', $this->_getEventData());
    $this->updateStoredData();
    return $this;
}

The problem is in magento in core file vendor\magento\module-catalog-inventory\Model\Stock\Item.php as we know we generate name of event using this $this->_eventPrefix this variable is not properly declared in item.php file

So change the line in vendor\magento\module-catalog-inventory\Model\Stock\Item.php around line number 35 from

protected $eventPrefix = 'cataloginventory_stock_item';

To

protected $_eventPrefix = 'cataloginventory_stock_item

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.