Magento – Override and extension class which in turn overrides a magento core class

extensionsoverrides

I have a requirement which would need me to write an extension that overrides a class from another extension which in turn uses the rewrite to override a core module.

Whilst I have the feeling that it would mostly relate to the config.xml file in my extension it have tried the following:

<config>
<modules>
    <Leafcutter_CustomMenu>
        <version>1.0</version>
    </Leafcutter_CustomMenu>
</modules>
<global>
    <blocks>
        <custom_menu>
            <rewrite>
                <topmenu>Leafcutter_CustomMenu_Block_Topmenu</topmenu>
            </rewrite>
        </custom_menu>
    </blocks>
</global>

With the above code what I am intending on doing is try to override the WP_CustomMenu_Block_Topmenu block from the custom menu extension, which in turn overrides the Mage_Page_Block_Html_Topmenu block.

I have tried the above but it keeps on getting the WP_CustomMenu_Block_Topmenu and not my extended class. I know that if I removed the above code and replaced it with this:

<config>
    <modules>
        <Leafcutter_CustomMenu>
            <version>1.0</version>
        </Leafcutter_CustomMenu>
    </modules>
    <global>
        <blocks>
            <page>
                <rewrite>
                    <html_topmenu>Leafcutter_CustomMenu_Block_Topmenu</html_topmenu>
                </rewrite>
            </page>
        </blocks>
    </global>
</config>

and removed the code responsible in the original plugin, I can achieve what I want. But for curiosity's sakes how would I override that extension without having to go into the config file in the extension and comment it out, as I consider this pretty hacky.

Thanks.

Best Answer

Your global node should be something like below

<global>
<blocks>
        <customMenu>
            <class>Leafcutter_CustomMenu_Block</class>
        </customMenu>
    <custom_menu>
        <rewrite>
            <topmenu>Leafcutter_CustomMenu_Block_Topmenu</topmenu>
        </rewrite>
    </custom_menu>
</blocks>

and extend extension's block class in your custom module block class

 <?php
   class Leafcutter_CustomMenu_Block_Topmenu extends WP_CustomMenu_Block_Topmenu
   {
        // create your method ans write your code
   }
Related Topic