In Magento, suppose we wanted to override/rewrite the core adminhtml block grid class which is originally based in app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php

To override a core adminhtml block grid, we need to do the following,

1. Create a new module named “AU_OverrideCatalogProduct”.

2. Create the global module config file in app/etc/modules/AU_OverrideCatalogProduct.xml with following content:

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

3. Create the module in “local” code-pool. The illustration would be as follows:

app/code/local/AU/OverrideCatalogProduct/etc/config.xml

app/code/local/AU/OverrideCatalogProduct/Block/Adminhtml/Catalog/Product/Grid.php

4. In module config file, which is app/code/local/AU/OverrideCatalogProduct/etc/config.xml, add the following content

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <AU_OverrideCatalogProduct>
            <version>0.0.1</version>
        </AU_OverrideCatalogProduct>
    </modules>

    <global>
        <blocks>
            <au_overridecatalogproduct>
                <class>AU_OverrideCatalogProduct_Block</class>
            </au_overridecatalogproduct>

            <!-- Overriding adminhtml block -->
            <adminhtml>
                    <rewrite>
                        <catalog_product_grid>AU_OverrideCatalogProduct_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
                    </rewrite>
            </adminhtml>

        </blocks>
    </global>

</config>

5. Ensure that our newly created

AU/OverrideCatalogProduct/Block/Adminhtml/Catalog/Product/Grid.php

extends from Mage_Adminhtml_Block_ Catalog_Product_Grid like below:

class AU_OverrideCatalogProduct_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{

}

 

That’s all. If we do have cache enabled, to see the effect clear the cache and should be fine.