Magento 1.6 – Problem with Overriding Observer

event-observermagento-1.6overrides

What I'm trying to do is to override one single method in Model/Observer.php of other module. I followed this tutorial: http://www.atwix.com/magento/overriding-observers/.

As a result I've created my own module.
Its etc\config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Package_MyModule>
            <version>1.0.0</version>
            <platform>ce</platform>
        </Package_MyModule>
    </modules>
    <global>
        <helpers>
            <mymodule>
                <class>Package_MyModule_Helper</class>
            </mymodule>
        </helpers>
        <models>
            <mymodule>
                <class>Package_MyModule_Model</class>
            </mymodule>
            <theirmodule>
                <rewrite>
                    <observer>mymodule/observer</observer>
                </rewrite>
            </theirmodule>
        </models>
    </global>
    <frontend>
        <events>
            <event_name>
                <observers>
                    <their_controller_predispatch>
                        <type>disabled</type>
                    </their_controller_predispatch>
                    <mymodule_controller_predispatch>
                        <type>singleton</type>
                        <class>mymodule/observer</class>
                        <method>someObserverMethod</method>
                    </mymodule_controller_predispatch>
                </observers>
            </event_name>
        </events>
    </frontend>
</config>

My observer class itself extends initial observer class (and also my module depends on initial module):

class Package_MyModule_Model_Observer extends Package_TheirModule_Model_Observer
{
    public function someObserverMethod($observer)
    {
        ...
    }
}

Initial module has several events, that are handled by that observer class (let's say, 10).

When I try to run my code I get the following error: "Mage registry key "_singleton/mymodule/observer" already exists". I've tried all solutions for this error from magento.stackexchange.com and none of them worked for me.

But, and that is interesting, when I add all other missed events to my config.xml (9 of those, that I do not want to override), everything works fine. But I do not want to do that, cause I lose advantages of overriding then.

So my question is: how to override only one method of observer of other module and not get this strange error?

Best Answer

I don't think the rewrite is required any more since you're already disabling their observer.

Do make sure to add their module as a dependency to your module

app/etc/modules/Package_Mymodule.xml

<config>
    <modules>
        <Package_MyModule>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Package_TheirModule />
            </depends>
        </Package_MyModule>
    </modules>
</config>
Related Topic