As you know, I had a guide “How to use Magento 2 events” before.
- Now I will help you how to create an event in your extension for Magento 2.
- This guide is so easy to do, so let’s enjoy it with these easy steps.
- Now I have a simple example:
$event_data_array = ['cid' => '123'];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$eventManager = $objectManager->create(‘\Magento\Framework\Event\Manager’);
As you can see it’s fairly straightforward to dispatch the event from almost anywhere in Magento 2.3. The first argument of the dispatch method is the name of the event and the second argument is used to pass the data to observers.
Your Magento website needs a powerful Magento ERP for stock control.
DON'T MISS THE CHANCE!