سؤال

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 ?

هل كانت مفيدة؟

المحلول

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top