Magento Override Core Blocks

You can override Magento core blocks file by following method.
Please find the sample code below:

1) When we override the blocks or methods of blocks in the module, we should not change the core block files directly. To do this, we add following xml in config.xml inside the our custom module:
<global>
<blocks>
<catalog>
<rewrite>
<new_block_key>Mynamespace_Test_Block_Catalog_Product</new_block_key>
</rewrite>
</catalog>
</blocks>
</global>

2) We create a new custom class in our block folder at path Mynamespace/Test/Block/Catalog/Product.php in our custom module.

<?php
class Mynamespace_Test_Block_Catalog_Product extends Mage_Catalog_Block_Product
{
}
Thats’s it! You have overrided the core block ‘Mage_Catalog_Block_Product’.

Leave a Reply