Magento Adminhtml – Fix Can’t Override Magento Adminhtml Block

adminhtmlblocksmagento-1.8overrides

Sysnopsis

I am trying to change a tab on the admin products page (grouped); However for some obscure reason I cannot get my module to work. The problem seems to be my module is completely ignored.

Code

app/etc/modules/Vendor_Catalog.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Vendor_Catalog>
            <active>true</active>
            <codePool>local</codePool>
        </Vendor_Catalog>
    </modules>
</config>

Vendor/Catalog/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Vendor_Catalog>
            <version>1.0.0</version>
        </Vendor_Catalog>
    </modules>
    <global>
        <blocks>
            <vendor_catalog>
                <class>Vendor_Catalog_Block</class>
            </vendor_catalog>
            <adminhtml>
                <rewrite>        
                    <catalog_product_edit_tabs_grouped>Vendor_Catalog_Block_Adminhtml_Catalog_Product_Edit_Tabs_Grouped</catalog_product_edit_tabs_grouped>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

Vendor/Catalog/Block/Adminhtml/Catalog/Product/Edit/Tabs/Grouped.php:

<?php
class Vendor_Catalog_Block_Adminhtml_Catalog_Product_Edit_Tabs_Grouped
    extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs
{
}

Best Answer

During my sleep I must have subconsciously thought of the solution; it would appear that I was overriding the wrong block for this scenario.

Also it appears to me that Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs_Grouped is either deprecated or just not used any more.

Nevertheless I added a die; statement inside the cores' protected function _prepareLayout() method - lo and behold nothing stopped processing. So I consult my best friend grep and found the following:

$ grep -r -e 'Associated Products' "app/code/core/Mage/"

A core block Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Group which I then decided to override - this worked (source attached for anyone else that has this problem).


Vendor/Catalog/etc/config.xml:

<config>

    ...

    <global>
        <blocks>
            <vendor_catalog>
                <class>Vendor_Catalog_Block</class>
            </vendor_catalog>
            <adminhtml>
                <rewrite>
                    <catalog_product_edit_tab_super_group>Vendor_Catalog_Block_Adminhtml_Catalog_Product_Edit_Tab_Super_Group</catalog_product_edit_tab_super_group>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>

    ...

</config>

Vendor/Catalog/Block/Adminhtml/Catalog/Product/Edit/Tab/Super/Group.php:

<?php

class Vendor_Catalog_Block_Adminhtml_Catalog_Product_Edit_Tab_Super_Group
    extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Group
{
    public function getTabUrl()
    {
        // Override the tab Url with my controller/action.
        return $this->getUrl('*/vendor_catalog_product/superGroup', array('_current' => true));
    }
}
Related Topic