4

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?

  • Try using the full class name in your config.xml <class>Package_MyModule_Model_Observer</class> see: stackoverflow.com/questions/19142720/… – B00MER Oct 21 '15 at 15:55
  • @B00MER, though it didn't help, I'd changed the name for consistency, thanks! – Gino Pane Oct 22 '15 at 8:12
2

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>
  • Dependency was added previously, so it was not the reason. But removing of rewrite actually helped! Thanks a lot! It's strange, cause I'm sure that I have tried to remove that section and haven't seen the difference. Maybe I just missed that:) – Gino Pane Oct 22 '15 at 8:15

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.