Is it possible to add an event (hook) to a core action without overriding it?
-
16-10-2019 - |
Question
I'd like to add a hook to a Magento core action (in this specific case Mage_Adminhtml_Sales_Order_CreateController::saveAction() but I hope there's a general solution).
Just a hunch, but it seems to me that there should be a way to add a hook to an action using Magento's XML, without having to override a class just to add a one-line Mage::dispatchEvent(). Perhaps this is wishful thinking.
Is there any way to do this using XML? Or no? If so, how?
Solution
Good news: you don't need to rewrite controllers to listen for it to be called. Magento has dynamic eventing that are called both before and after a controller action is fired.
In your case all you would have to listen for is controller_action_predispatch_adminhtml_sales_order_create_save
.
In the case that you would want to listen for after the action has completed and just prior to the request completion, you would change predispatch
to postdispatch
.
More reading: https://magento.stackexchange.com/a/5614/336