Magento allows many different ways of modules’ customization, overriding methods and using events being the recommended ones.
While overriding methods is the most flexible way, it is sometimes more convenient to use Event Observers that perform actions on Event Dispatches in key spots.
Event Observer implementation (in custom module’s models):
class Mage_MyModule_Model_Observer { public function some_event_handle($observer) { $event = $observer->getEvent(); $order = $event->getOrder(); $customer = $event->getCustomer(); // ... add my custom code to be spawned during the event // ... may update the argument objects, or do any other action. } }
As you can see, events are a powerful mechanism providing plug and play interface for your customizations.
This thread is meant for developers, which feel that core modules missing event dispatches in key spots, would benefit majority of Magento developers and should be included with default distribution.
thanks for that snippet, its a good idea i think. But for me right now its hard to understand architecture and working of magento… I tried your NewPayment Tutorial but it doesnt work, see my topic...! The last week i used much time to understand architecture and working of magento. Ill report if i had sucess creating my own paygate for cc.
* a quote_item gets turned into an order_item (I think this one is done)
* a catalog_product gets turned into a quote_item
* before and _before_ a customer logs-in and logs-out (great for doing CMS integration with a just a helper)
* before and after a customer changes some profile data (ditto)
* When someone views an item (might give ability to track some stats separately, or double check inventory)
* before and after someone removes an item from the cart
* before and after someone changes quantity in the cart
* before and after any emails are sent to any customer
* before and after any payment gateways are created and/or used
The cart quantity and delete ones I was thinking about making some offers, like buy one get one free. Well, you don’t want them buying one, and then deleting the one they have to pay for. Or, buying one and then changing the quantity of the free one… so listening to those events would be helpful.
Before and after emails would allow someone to check another list of do-not-mail or another subscription list before sending. After sending they can log the mail to a special database or something without having to override the entire method.
Payment gateways… just seems like someone would want to be notified of that stuff. Perhaps to unencrypt a key, or to trigger an email if an order is over X amount of dollars (maybe to watch it for fraud).
I second this as it will help a lot while integrating magento with other systems.
before/after user regsitration/profile changes/user removal is a _must_
I’m not sure which events are already implemented. But I would like to add to the list:
- before/after page loads
- before/after logout would be nice as well.
- before search could be useful to trigger external search mechanisms (services?)
events during cart submission/modification as Mark suggested are a really good idea.
Thought a wiki would best describe usage of this functionality. Didn’t have the time to fully document the code and list of events. I have extracted a list of events that magento currently supports in its code. Please have a look at
Customization using Event-Observer Wiki
Thought a wiki would best describe usage of this functionality. Didn’t have the time to fully document the code and list of events. I have extracted a list of events that magento currently supports in its code. Please have a look at
Customization using Event-Observer Wiki
thanks for providing the list. Now we just need to find out when these events are called
Will these events be raised even during product import process? say, will ‘catalog_product_save_after’ be raised after importing the product using bulk import functionality?
within Onepage chekcout it would be great to have some more observers for saving additional customer/address data. This could be very helpful to implement german and european needs at registration of customers. i had to overload saveorder to save additonal datas if user isnt registrated.
Personally, I think it would be great to go maximum flexibility and expose event dispatch in a way that we could specify the method in which we need the event to occur, and then after what call we want it to occur, since an event always happens after some method is called, it would make it so much easier if the core provided the inherent functionality to register our own event dispatches only by requiring certain information which we would simply find and refer to from the source code.
All that being said, I need an event dispatch for the CartController in the Checkout module - specifically for deleteAction() for a module I’m working on.
Oh, and by the way. You have no idea how happy I am that you’ve integrated the event dispatch system. NO IDEA!!!
Personally, I think it would be great to go maximum flexibility and expose event dispatch in a way that we could specify the method in which we need the event to occur, and then after what call we want it to occur, since an event always happens after some method is called, it would make it so much easier if the core provided the inherent functionality to register our own event dispatches only by requiring certain information which we would simply find and refer to from the source code.
That would dangerously couple your event handler to the internal workings of the core - sure it would give you more control but it’d be fragile, breaking if so much as a method name was changed. If you’re going to be that tightly coupled, you might as well just modify the class directly.