DEV Community

Graham Crocker
Graham Crocker

Posted on • Updated on

Investigating which events are being dispatched in Magento2

There are cases when certain events expected to be dispatched aren't, such as with product MassUpdate and individual product edit. Individual product edit dispatches catalog_product_save_after, but this does not apply to MassUpdate so we must investigate which events can be hooked in.

Go to vendor/magento/module-staging/Model/Event/Manager.php and in function dispatch below $eventName variable declaration add the following:

$eventName = mb_strtolower($eventName);
Enter fullscreen mode Exit fullscreen mode
// devmod start
$filename = BP . '/var/log/events.log';

$writer = new \Zend\Log\Writer\Stream($filename);
$logger = new \Zend\Log\Logger();
#Fix for 2.4.x below
$logger->addWriter($writer);
$logger->info($eventName);
// devmod end
Enter fullscreen mode Exit fullscreen mode

Magento 2.4.x Fix

$writer = new \Zend_Log_Writer_Stream($filename);
$logger = new \Zend_Log();
Enter fullscreen mode Exit fullscreen mode

Before running your Magento process or journey

tail -f /tmp/events.log

E.g. Search and investigate events
cat /tmp/events.log | grep catalog_product
cat /tmp/events.log | grep save_after
cat /tmp/events.log | grep update_before
cat var/log/events.log| grep save_after | grep -v model | grep -v theme

Top comments (0)