Tuesday 20 October 2015

How to override Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select block in Magento

Sometimes you need to change the behavior of Magento core functionality and add our custom code and it's a bad habit and bad programming if core files are modified and it's not recommended at all.Magento brought in an excellent way how to override/overwrite those files for adding our custom code.

Overriding Magento Blocks

Here we will see how to change a basic block of Magento. Suppose that in Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select class we need to add some changes have to be done. What we would like to have here is to add our own file that will extend the original file with all of its methods. All the job that has to be done is to add the code below in the current module's config.xml:

Step 1:- Start rewriting the Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select block in config.xml of your custom module

<config>
<global>
<blocks>
<adminhtml>
            <rewrite>
                <catalog_product_edit_tab_options_type_select>
                    [YourPackageName]_[YourModuleName]_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_Select
                </catalog_product_edit_tab_options_type_select>
            </rewrite>
        </adminhtml>
</blocks>
</global>
</config>

Step 2:- create the file and add your code modification in this class of the respective method from the core block class.

As the class name says, a file has to be created in app/code/local/YourPackageName/YourModuleName/Block/Adminhtml/Catalog/Product/Edit/Tab/Options/Type/Select.php and a class has to be defined:

class [YourPackageName]_[YourModuleName]_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_Select extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select{
// your code
}

No comments:

Post a Comment