1

I would like to override a specific block of a module that I've downloaded, because there is a specific methods I would like to add, and I don't like the idea of modifying module's core files.

I have hard time to structure my xml correctly, which is why my block does not gets loaded instead of the original one. I've tried following the tips provided by @Joseph in this question, but no luck.

Now, let me provide some file structure.

The interesting part of the downloaded module config.xml

<?xml version="1.0"?>
    <config>
        <modules>
            <EM_Megamenupro>
                <version>1.0.0</version>
            </EM_Megamenupro>
        </modules>
        <blocks>
            <megamenupro>
                <class>EM_Megamenupro_Block</class>
            </megamenupro>
        </blocks>
    </config>

The block I am trying to modify is located in app/local/EM/Megamenupro/Block/Megamenupro.php

Now, my module is located in app/local/Acme/Demo, my block is located in app/local/Acme/Demo/Block/Megamenu.php

My module is active(I checked it up in Administrative panel, its there)

In my config.xml file I've added the following nodes, but it does not appear to be working.

<global>
    <blocks>
        <megamenupro>
            <rewrite>
                <megamenu>Acme_Demo_Block_Megamenu</megamenu>
            </rewrite>
        </megamenupro>
    </blocks>
</global>

Any kind of help would be kindly appreciated. Thank you.

5

Your config.xml should look like this:

<global>
    <blocks>
        <megamenupro>
            <rewrite>
                <megamenupro>Acme_Demo_Block_Megamenu</megamenupro>
            </rewrite>
        </megamenupro>
    </blocks>
</global>

As a general rule:
The config in the original extension states this:

<blocks>
    <megamenupro>
        <class>EM_Megamenupro_Block</class>
    </megamenupro>
</blocks>

You need to rewrite EM/Megamenupro/Block/Megamenupro.php that is referenced internaly as megamenupro/megamenupro.
Your config should look like this

<global>
    <blocks><!-- you are rewriting a block -->
        <megamenupro><!-- the same tag as in the original extension under the <blocks> tag -->
            <rewrite> <!-- this is fixed -->
                <megamenupro>Acme_Demo_Block_Megamenu</megamenupro><-- this tag should be what's after the `Block/` part in the class you want to rewrite. so  -EM/Megamenupro/Block/Megamenupro.php becomes 'megamenupro'->
            </rewrite>
        </megamenupro>
    </blocks>
</global>
  • Thank you very much. Tho there was a typo at first, I got your idea and it worked like a charm. I appreciate your help. I will accept it as correct in a while (when the system allows me to) – user26123 May 21 '15 at 11:04
  • Sorry for the typo. I saw it and fixed it. – Marius May 21 '15 at 11:14
0

I'll add to this since this is related, My original problem was I have customerprice module and it's overriding the Mage_Adminhtml_Block_Customer_Edit_Tabs

I had to include a tab on admin customer menu. Here is how I manage

Your customerprice module config.xml

<blocks>
    <adminhtml><!-- remember this admin html -->
        <rewrite>
            <catalog_product_edit_tabs>Webtex_CustomerPrices_Block_Adminhtml_Catalog_Product_Tabs</catalog_product_edit_tabs>
            <customer_edit_tabs>Webtex_CustomerPrices_Block_Adminhtml_Customer_Edit_Tabs</customer_edit_tabs>
        </rewrite>
    </adminhtml>
</blocks>

My custom module config.xml

<adminhtml>
    <rewrite>
        <customer_edit_tabs>Forge_Mymodule_Block_Adminhtml_Customer_Edit_Tabs</customer_edit_tabs>
    </rewrite>
</adminhtml>

And in my Customer/Edit/Tabs.php

class Forge_Mymodule_Block_Adminhtml_Customer_Edit_Tabs 
    extends Webtex_CustomerPrices_Block_Adminhtml_Customer_Edit_Tabs
{

    protected function _beforeToHtml()
    {
            $this->addTab('acumen_tab', array(
                'label'     => Mage::helper('acumen')->__('Acumen Information'),
                'content'   => $this->getLayout()
                    ->createBlock('acumen/adminhtml_customer_edit_tab_account')->toHtml(),
            ));
        return parent::_beforeToHtml();
    }
}

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.