B-219 Sec-55 Noida, India
+918010221733

Create custom event in magento.

Use below 2 magneto event to dispatch event in magento
<controller_action_predispatch>
<observers>
<pioc_backoffice_shipping_observer>
<class>PIOC_Backoffice_Model_Shipping_Observer</class>
<method>hookToControllerActionPreDispatch</method>
</pioc_backoffice_shipping_observer>
</observers>
</controller_action_predispatch>
<controller_action_postdispatch>
<observers>
<pioc_backoffice_shipping_observer>
<class>PIOC_Backoffice_Model_Shipping_Observer</class>
<method>hookToControllerActionPostDispatch</method>
</pioc_backoffice_shipping_observer>
</observers>
</controller_action_postdispatch>
The below are 2 custom event that we have dispathced at particular point of execution
<pioc_backoffice_shipping_save_before>
<observers>
<pioc_backoffice_shipping_observer>
<type>singleton</type>
<class>PIOC_Backoffice_Model_Shipping_Observer</class>
<method>pioc_shipping_save_before</method>
</pioc_backoffice_shipping_observer>
</observers>
</pioc_backoffice_shipping_save_before>
<pioc_backoffice_shipping_save_after>
<observers>
<pioc_backoffice_shipping_observer>
<type>singleton</type>
<class>PIOC_Backoffice_Model_Shipping_Observer</class>
<method>pioc_shipping_save_after</method>
</pioc_backoffice_shipping_observer>
</observers>
</pioc_backoffice_shipping_save_after>
———Function in observer class to dispatch events——————–
public function hookToControllerActionPreDispatch($observer)
{
//we compare action name to see if that’s action for which we want to add our own event
if($observer->getEvent()->getControllerAction()->getFullActionName() == ‘canvassizecat_adminhtml_myform_post’)
{
//We are dispatching our own event before action ADD is run and sending parameters we need
Mage::dispatchEvent(“pioc_backoffice_shipping_save_before”, array(‘request’ => $observer->getControllerAction()->getRequest()));
}
}
public function hookToControllerActionPostDispatch($observer)
{
if($observer->getEvent()->getControllerAction()->getFullActionName() == ‘canvassizecat_adminhtml_myform_post’)
{
//We are dispatching our own event before action ADD is run and sending parameters we need
Mage::dispatchEvent(“pioc_backoffice_shipping_save_after”, array(‘request’ => $observer->getControllerAction()->getRequest()));
}
}

(Visited 56 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.