Magento News

 

Magento: Event Observer Scope

I learned a valuable lesson this weekend (the hard way of course) when it comes to event observers in Magento. You’ve got 3 different places to setup your event observers in your config.xml file of your modules. They are as follows:

<config>
    <frontend>
        <events>
            ...
        </events>
    <frontend>
    <adminhtml>
        <events>
            ...
        </events>
    <adminhtml>
    <global>
        <events>
            ...
        </events>
    <global>
</config>

It is pretty self-explanatory, but here’s how it works: Events are firing off all the time. If you are needing to observe an event, but only when it happens on the frontend, then you would put your observer in the ‘‘ section. That same event might also be fired off in the admin, but your module won’t observe that event from the admin if you have it in ‘‘. If you want the event to be observed no matter where it happens (admin or frontend), you would then put your observer in the ‘‘ section.

I was trying to observe an event that should be fired off when an order is edited in the admin. I wasn’t able to log anything in my observer at all, and I couldn’t figure out why. Turns out it was because I had the event observer in the ‘‘ section. I changed it to ‘‘ and then it worked just fine.


Magento: Event Observer Scope

Possibly Related Posts:


 

Leave a Reply