Question

help me find event magento2. In magento we have event catalog_product_after_save this event in magento2-rc?

Was it helpful?

Solution

In Magento 2 I'm also tried to view the same event in my custom module requirement but unable to find out.

after create log from root\lib\internal\Magento\Framework\Event\Manager.php file and open admin panel create one product after you can see the logs catalog_product_after_save event as well product id

public function dispatch($eventName, array $data = [])
    {

       $this->logger->info($eventName);

        \Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]);
        foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
            $event = new \Magento\Framework\Event($data);
            $event->setName($eventName);

            $wrapper = new Observer();
            $wrapper->setData(array_merge(['event' => $event], $data));

            \Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
            $this->_invoker->dispatch($observerConfig, $wrapper);
            \Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
        }
        \Magento\Framework\Profiler::stop('EVENT:' . $eventName);
    }

crete events.xml file in etc/adminhtml/ folder and paste the below code

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
    <event name="catalog_product_after_save">
        <observer name="custom_event" instance="Learning\Custom\Model\Observer" method="getProduct" />
    </event>   
</config>

and Observer.php write below method

public function getProduct(\Magento\Framework\Event\Observer $observer)
    {

        $product_id = $observer->getProduct()->getId();
        $this->logger->info($product_id );
    }

Above Magento 2.0.0rc changed the observer syntax to execute as shown below.

public function execute(\Magento\Framework\Event\Observer $observer)
    {
 $product_id = $observer->getProduct()->getId();
            $this->logger->info($product_id );
    }

OTHER TIPS

In the file "lib/internal/Magento/Framework/Model/AbstractModel.php" you can find method "afterSave" and line with $this->_eventManager->dispatch($this->_eventPrefix . '_save_after'....

"_eventPrefix " for Product model is "catalog_product", so the full name for event is "catalog_product_save_after"

Also, you may be interested in using M2 "Interceptors/Plugins", you can find many examples in M2 code base (see di.xml declaration "plugin" node)

The event you are looking for is controller_action_catalog_product_save_entity_after

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top