Latching onto magento events is very simple – however, after a lot of searching I couldn’t find a lot of resources documenting how to do it.
I’ll more than likely research magento events a bit more in a later post, but for reference here is a cheatsheet of dispatched magento events Credit: Branko Ajzele of Active Codeline. (a little outdated – from version 1.3)
Let’s keep it simple…
The namespace for my module will be “Ifuel”
The name of my module will be “Aftercheckout”
I will want to latch onto one of the many dispatched events during the checkout process (to name a few: checkout_controller_onepage_save_shipping_method, sales_order_place_after, checkout_type_onepage_save_order_after, checkout_onepage_controller_success_action). For reference about checkout events, check out Yireo’s Events with Magento Checkout. For this module, I want to execute my class after the order has been completely checked out – so I will latch onto the “checkout_onepage_controller_success_action” event.
Here is the bare bones of my config.xml file located at /app/code/local/Ifuel/Aftercheckout/etc/config.xml. Make sure to read the comments in the code, they’re helpful. P.s. don’t forget to declare your module in /app/etc/modules/
Now you’ll want to create your Listener. In my case it will be located at /app/code/local/Ifuel/Aftercheckout/Model/Doaftercheckout.php. Make sure to create a public function within your new class that you’ve defined in the <method> node of your config.xml file. The contents of my listener will look something like: