The coolest thing about Magento is that it supports the Event-driven programming model. The event simply means action and it can be anything like user actions, mouse click, system occurrences or anything. And the system which responds to events is generally known as an event-driven programming language. The entire concept is pretty straightforward. When an event gets fired, and your observers catch the event and executes a certain piece of code. And the Best part in that, you can write your custom code apart from the core modification.
In Magento 2, events can be dispatched using the Magento\Framework\Event\Manager class. While developing a custom extension, we need to create a custom dispatch event, so in future, if any other developer needs to extend functionality at that time they can use this dispatch event. So, here it goes.

In the first step, we need to create “My event.php” file to perform particular action.
app\code\vendor\extension\Controller\Index\Myevent.php

In next step, we need to create “events.xml” file for calling custom dispatch event.
app\code\vendor\extension\etc\frontend\events.xml

In last step, we need to create Event Observer file by creating “Updatevalue.php”.
app\code\vendor\extension\observer\Updatevalue.php

That’s it! You have successfully created your custom dispatch event in Magento 2. You are free to play and manipulate this according to your need for creating custom dispatch event in Magento 2 Extension.
That’s it for today, Let us know if you are facing an issue while implementing using this code by commenting below.
Happy Coding!

Click to rate this post!
[Total: 11 Average: 4.3]