How to disable and/or override an observer in Magento

Magento

If you develop application based on megento, sometimes we need to modify or even to disable some feature found in observer class.

Normally an observer is a model and can be overridden like a usual model using rewrite tag. Sometimes this method not work so in this article i describe a new method to disable or disable and override an observer.

 

Disabling an observer can done from etc/config.xml found in any module, using a code like below:

    <admin_user_authenticate_after>
        <observers>
            <enterprise_pci>
                <type>disabled</type>
            </enterprise_pci>
        </observers>
    </admin_user_authenticate_after>

Code from above it will disable an magento enterprise observer called on event "admin_user_authenticate_after"

Now if we want to replace functionality of that observer with another observer, our observer, we can add new observer on same event like this:

    <admin_user_authenticate_after>
        <observers>
            <enterprise_pci>
                <type>disabled</type>
            </enterprise_pci>
            <mynamspace_mymodule>
                <type>singleton</type>
                <class>mynamspace_mymodule/pciobserver</class>
                <method>adminAuthenticate</method>
            <mynamspace_mymodule>
        </mynamspace_mymodule></mynamspace_mymodule></observers>
    </admin_user_authenticate_after>

So basically we overridden enterprise observer with our observer. In order to this works do not forget to set dependencies in your custom module to module to wich you want to override or disable observer.

In more detail we overridden only one event (admin_user_authenticate_after) from that observer class if that class contains methods that listen to other events, that ones not be overwritten.


Add comment
 
 
 

Comments