Featured post

Magento® 2.x How to create basic frontend module

How to create basic frontend module in Magneto 2 ?? Step 1. Decide a name space(Extendtree) & module name(Helloworld). Ex. Extendtre...

Saturday, 3 September 2016

Magento® 2.x Create Custom Event

How to create custom events in Magneto 2 ??


Step 1. app/code/Extendtree/Customevent/etc/events.xml

<!--xml version="1.0"?--> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="custom_event_name_here"> <observer name="custom_observer_name_here" instance="Extendtree/Customevent/Observer/Observer.php" /> </event> </config>

Step 2. Dispatch the event.

$this->_eventManager->dispatch('custom_event_name_here',['some_value => 1]);

Step 3. Create Observer file & declare method in app/code/Extendtree/Customevent/Observer/Observer.php

namespace Extendtree\Customevent\Observer; use Magento\Framework\Event\ObserverInterface; class Observer implements ObserverInterface{ public function __construct() {} public function execute(\Magento\Framework\Event\Observer $observer){ /**************Do Something****************/ /**************Do Something***************/ } }


Thank you..!!

"The easy way for everything."

No comments :

Post a Comment