Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

override block only from specific module
 
rgoodrow
Member
 
Total Posts:  31
Joined:  2013-04-23
 

through following various guides online, I’ve managed to override a core Magento Block with my own block (specifically Mage_Catalog_Block_Product_List_Toolbar)

The following is the code I have

/app/etc/modules/My_Custom.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
My_Custom>
            <
active>true</active>
            <
codePool>local</codePool>
        </
My_Custom>
    </
modules>
    <
blocks>
        <
My_Custom>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends>
                <
Mage_Catalog />
            </
depends>
        </
My_Custom>
    </
blocks>
</
config>

/app/code/local/My/Module/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
My_Custom>
            <
version>1.0.0</version>
        </
My_Custom>
    </
modules>
    <global>
        <
blocks>
            <
catalog>
                <
rewrite>
                    <
product_list_toolbar>My_Custom_Block_Product_List_Toolbar</product_list_toolbar>
                </
rewrite>
            </
catalog>
        </
blocks>
    </global>
    <
frontend>
        <
routers>
            <
bookshelf>
                <use>
standard</use>
                <
args>
                    <
module>My_Custom</module>
                    <
frontName>custom</frontName>
                </
args>
            </
bookshelf>
        </
routers>
        <
layout>
            <
updates>
                <
custom module="My_Custom">
                    <
file>custom.xml</file>
                </
custom>
            </
updates>
        </
layout>
    </
frontend>
</
config>

I can verify that it is using both the new block controller file (/app/code/local/My/Custom/Block/Product/List/Toolbar.php) & template file (/app/design/frontend/consumer/default/template/catalog/product/list/toolbar.phtml)

however the problem is that it’s loading the overloading the block for every module on the site, not just the specific Custom module. I’m fairly certain that it’s because of the <global></global> tags in the config.xml, however if I remove them, then it reverts back to the core controller.

How can I make just the specific My/Custom module use the overloaded block, but all other modules use the standard block?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

what you need is not override, simply call your custom blocks in your custom module, thats it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rgoodrow
Member
 
Total Posts:  31
Joined:  2013-04-23
 

thank you.

I arrived at the same conclusion myself.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top