5

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.

2
  • Can you put the extension's config.xml here.
    – Sukeshini
    Commented Oct 21, 2013 at 3:42
  • 1
    Make you extension depend on the WP_CustomMenu extension by adding in etc/modules/Leafcutter_CustomMenu.xml this <depends><WP_CustomMenu /></depends>
    – Marius
    Commented Oct 21, 2013 at 6:42

1 Answer 1

1

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
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.