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’.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s