16

Is there any complete list of events in Magento 2? I'm looking for something like Magento Events Cheat Sheet (1.9)

18

I put together a list of Magento 2 events using

find . -type f -exec grep -n -H -A 2 -T "eventManager->dispatch(" {} \;

The list is divided in 2 parts, one for static events and one for dynamics.

From here, static events are all those events defined with full event name like:

$this->_eventManager->dispatch('some_event');

Dynamic events are all those events defined with dynamically, at runtime, fetched event name like:

$this->_eventManager->dispatch($this->_eventPrefix . '_load_before', $params);

The list is in a spreadsheet for a better reading. I left 2 lines after the match for a better understanding of the event context.

The same list can be found searching in the official Magento 2 repo for _eventManager->dispatch

  • The list is very helpful but it seems incomplete. The event sales_order_save_after for example which is pretty important for my current task is missing and when you search through the Magento 2 repo you'll notice that there is no dispatch at all for it: github.com/magento/magento2/… I have no idea yet how these events are dispatched but it would be great to include them in the list! – Jey DWork Jul 11 '16 at 20:13
  • How do you know the event name of it doesn't exist? Maybe you are looking for an equivalent in Magento 2 with another name? – mbalparda Jul 11 '16 at 20:50
  • Not sure if we are talking about the same thing. I was just wondering why the event sales_order_save_after (just as one example) doesn't come up in the list (and the search) also it also doesn't look like a dynamic event. And then I was thinking if and how it could be possible to include such events to get a more complete list. And obviously I'm only talking about Magento 2 sales_order_save_after is a Magento 2 event, too as far as I can tell. – Jey DWork Jul 11 '16 at 21:02
14

Obviously, not a good practice, but i am providing one link which has complied the important events in Magento2

http://cyrillschumacher.com/magento2-list-of-all-dispatched-events/

Ofcourse the events list is incomplete, as if you have worked with Magento 1.x, the events dispatch logic is retained

  1. lib/internal/Magento/Framework/Model/AbstractModel.php Load before and after events of a model

    $this->_eventManager->dispatch($this->_eventPrefix . '_load_before', $params);
    $this->_eventManager->dispatch($this->_eventPrefix . '_load_after', $params);
    

    Save before and after events of a model object

    $this->_eventManager->dispatch($this->_eventPrefix . '_save_before', $this->_getEventData());
    $this->_eventManager->dispatch($this->_eventPrefix . '_save_after', $this->_getEventData());
    

    Deleting a object

    $this->_eventManager->dispatch($this->_eventPrefix . '_delete_before', $this->_getEventData());
    $this->_eventManager->dispatch($this->_eventPrefix . '_delete_after', $this->_getEventData());
    

    Clearing an object

    $this->_eventManager->dispatch($this->_eventPrefix . '_clear', $this->_getEventData());
    
  2. Controller dispatch

    lib/internal/Magento/Framework/App/Action/Action.php

    $this->_eventManager->dispatch(
        'controller_action_predispatch_' . $request->getFullActionName(),
        $eventParameters
    );
    
    eg // controller_action_predispatch_checkout_cart_index
    
    
    $this->_eventManager->dispatch(
        'controller_action_postdispatch_' . $request->getFullActionName(),
        $eventParameters
    );
    eg // controller_action_postdispatch_checkout_cart_index
    
  3. Frontend layout render events

    $this->_eventManager->dispatch(
        'controller_action_layout_render_before_' . $this->_request->getFullActionName()
    );
    
  4. Collections of Models

    lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php

    $this->_eventManager->dispatch($this->_eventPrefix . '_load_before', [$this->_eventObject => $this]);
    
    $this->_eventManager->dispatch($this->_eventPrefix . '_load_after', [$this->_eventObject => $this]);
    

There are many such events, and it is a combination of explicitly and implicitly generated events in Magento2

  • Good stuff! We should merge our answers to have everything in one place. What do you think? – mbalparda Oct 27 '15 at 7:44
  • well your answer too is self-sufficient – huzefam Oct 28 '15 at 6:12
1

The answers above all work great, but sometimes you need to know what events are thrown on a specific page load and the order they are thrown in.

So there here is the best way (in my opinion to know this), use xDebug and set a break point on line 56 in the class Magento\Framework\Event\Manager (it's in the lib folder not the app folder).

In your debugger just tell it to "Evaluate and log" the $eventName variable and watch all the events display in the console as you load the page.

I would also recommend disabling the "Suspend" option since there might be hundred of events thrown, you might need to leave it on for the first breakpoint to be hit and then you can remove it.

Event names breakpoint Why I think this is the best way to get all the events dispatched on a page load is because this will also show you all the events that are dispatched by controllers. Each controller dispatches events on before and after with composed names containing the FullActionName, RouteName and the default postdispatch one. See the Framework\App\Action class under the dispatch() method.

0

Its difficult to get the event to know in a specific page. So you can try this code to track the events getting called and use the best one for your needs

/vendor/magento/framework/Event/Manager.php

add this code below event name

$eventName = mb_strtolower($eventName);

// Code to log all events start
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$dirList = $objectManager->get('\Magento\Framework\App\Filesystem\DirectoryList');
$logPathName = $dirList->getPath('var') . '/log/events.log';
$eventLogFile = fopen($logPathName, 'a');
fwrite($eventLogFile, $eventName . ' => ' . implode(', ', array_keys($data)) . "\n");
fclose($eventLogFile);
// Code to log all events ends

You can check the list in <magentoroot>/var/log/events.log

-1

You may check below link of events https://github.com/matinict/Magento-2-Events

i suffer that different people share different event but no accuracy lost my time at last its just tricks go to your magento 2 vendor check etc/event.xml , Hope it may be help to magento 2 developer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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