I have an observer for sales_order_place_after and this is working. Now I am generating an order myself and would like to trigger this event but it does not get to my observer.

Is something wrong here:

Mage::dispatchEvent('sales_order_place_after', array('order' => $service->getOrder()));

Or do I need to do something special from a external script file? My script looks like this.

  • 4
    My current guess is that you are observing the event in a different scope to what the script is running in. Try placing the event observer in the global section. – Kristof at Fooman Sep 9 '13 at 16:10
  • @Fooman, this is an answer :) – Fabian Blechschmidt Sep 9 '13 at 18:38
  • @Fooman Yes, that's it! Would you like to post it as an answer? – PiTheNumber Sep 10 '13 at 7:48

Looks like my guess was correct.

In your config xml file you are only observing the event in one scope (for example frontend). However your script is running in a different scope. Placing the event into the global section of your config file should take care of this.


Came across the same problem where the event wasn't fired in my external script.
Depending on the scope of your observer in the config.xml you have to set the Event Area.

require_once 'app/Mage.php';

Mage::app()->addEventArea('global'); // e.g. 'global', 'frontend', 'adminhtml'

See also this article.


Replace the event to sales_order_save_after, this should be triggered from frontend, admin and custom scripts.

  • Thank youm, but same problem: Event wasn't triggered. – PiTheNumber Sep 10 '13 at 7:46
  • It might be an option to trigger an event from your import script and listen for that Mage::dispatchEvent('your_custom_event', array('order'=>$order)); – Sander Mangel Sep 10 '13 at 8:08
  • I tried that, did not work but solution is above in the comments. Just waiting for Fooman to post it. – PiTheNumber Sep 10 '13 at 10:57

I am sure the best solution if you only need to trigger the event on one specific area is to instantiate the State object and use setAreaCode() method and this will trigger the event in its corresponding area. Events are configured to run in their intended area, you cannot change their area; you only can trigger from that area.

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.