0

I need, on website save, get the inventory with the current website ID.

Ad I'm trying to get the CatalogInventory Stock Collection in an Observer, but it finish with the error:

Configuration array must have a key for 'dbname' that names the database instance

My Code is:

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $stockCollection = $objectManager->create('\Magento\CatalogInventory\Model\ResourceModel\Stock\Collection');
}

The event is: website_save_after

What is wrong with this?

I used this example: Magento 2 Get product collection

6
  • For which event you try?
    – Sohel Rana
    Commented Jul 16, 2016 at 18:58
  • <event name="website_save_after"> Commented Jul 16, 2016 at 18:59
  • What is your exactly need? You try to pick wrong collection.
    – Sohel Rana
    Commented Jul 16, 2016 at 19:04
  • I need, on website save, get the inventory with the current website ID Commented Jul 16, 2016 at 19:11
  • What exactly do you mean by inventory? In your code you're trying to load a collection of "Stock" objects. Is that what you are referring to as inventory here? Commented Jul 17, 2016 at 19:20

0

Your Answer

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