I'm new to magento and i don't have any idea about how I can run specific PHP function when user order completion.
can anyone explain me how I can do this?
I read about event/observer but I don't understand how to use


An "observer" is a fancy name for a method on a class definition that is executed on an event. Any number of observers can be fired for any one event.

To create one you first create a module. In the module config.xml definition locate (or create) the <global>, <frontend> and <adminhtml> nodes. You can create the event listener in any one of those 3 nodes. To register it, do the following:


To get a list of valid event names you can visit this site here.

In your module, create a class file called Observer.php in the Model directory. It will look something like:

class YourCompany_YourModule_Model_Observer
    public function methodName($observer)
        //observer data is in $observer->getEvent()

From there, whenever the event name you're listening to is called, your module's Observer model will be loaded and the method you've registered will fire.

| improve this answer | |
  • Thanks, I do what you told but nothing will happen, I was observe event customer_login and place die; on method but nothing will happen, I placed <events> in <frontend> – Farnabaz Mar 10 '14 at 22:03
  • I found where I missed up, thank you very much, but what event should observe for order completion? – Farnabaz Mar 10 '14 at 22:12
  • sales_order_place_after is always a good bet - but be careful; exceptions raised in this event may prevent order entry. – philwinkle Mar 10 '14 at 23:00
  • thank you very much, can you please place event name in your answer, for other who has same question @philwinkle – Farnabaz Mar 10 '14 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.