0

I have tried to call my observer when stock is updated. Here is my etc/adminhtml/events.xml code

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="cataloginventory_stock_item_save_after">
        <observer name="tct_stock_item_save_observer" instance="Namespace\Module\Observer\Notifier" />
    </event>
</config>

And here is my observer's code

<?php

namespace Namespace\Module\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use \Psr\Log\LoggerInterface;

class Notifier implements ObserverInterface {

  public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    LoggerInterface $logger
  ) {
    $this->_storeManager = $storeManager;
    $this->logger = $logger;
  }


  public function execute(Observer $observer) {
    $this->logger->warn('Observer Works');
    die('test');
  }

}

I have tried magento 2 event cataloginventory_stock_item_save_after but that didn't work.

But its not working. Please help.

1
  • I have tried that already. That didn't work then I had to raise a new query.
    – Manish Joy
    Jun 29 '17 at 7:30
1

You an try this its working for me.

app\code\YOUR_NAMESPACE\YOURMODULE\Observer\

<?php

namespace YOURNAMESPACE\YOURMODULENAME\Observer;

use Magento\Framework\Event\ObserverInterface;

class Productsaveafter implements ObserverInterface
{    
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $_product = $observer->getProduct();  // you will get product object
        $_sku=$_product->getSku(); // for sku

    }   
}
3
  • for the same event??
    – Manish Joy
    Jun 29 '17 at 6:11
  • yes you can implement that for the same event Jun 29 '17 at 6:12
  • I tried die($_sku); but after saving the product it didn't work.
    – Manish Joy
    Jun 29 '17 at 7:04

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