How to Rewrite / Override block in magento
Here we are Overriding / Rewriting magento block of Mage_Catalog_Block_Product_View with custom module named Chand_Software.
(1) Create module file in app/etc/modules/Chand_Software.xml
<?xml version="1.0"?>
<config>
<modules>
<Chand_Software>
<active>true</active>
<codePool>local</codePool>
</Chand_Software>
</modules>
</config>
(2) Create module config file in app/code/local/Chand/Software/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Chand_Software>
<version>1.0.0</version>
</Chand_Software>
</modules>
<global>
<blocks>
<catalog> // This is the block identifier which we want rewrite
<rewrite>
<product_view>Chand_Software_Block_Product_View</product_view>
</rewrite>
</catalog>
</blocks>
</global>
</config>
(3) Now Create block file of our custom module in app/code/local/Chand/Software/Block/Product/View.php
class Chand_Software_Block_Product_View extends Mage_Catalog_Block_Product_View
{
/**
* Put your logic here
*
*/
}
Here we are Overriding / Rewriting magento block of Mage_Catalog_Block_Product_View with custom module named Chand_Software.
(1) Create module file in app/etc/modules/Chand_Software.xml
<?xml version="1.0"?>
<config>
<modules>
<Chand_Software>
<active>true</active>
<codePool>local</codePool>
</Chand_Software>
</modules>
</config>
(2) Create module config file in app/code/local/Chand/Software/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Chand_Software>
<version>1.0.0</version>
</Chand_Software>
</modules>
<global>
<blocks>
<catalog> // This is the block identifier which we want rewrite
<rewrite>
<product_view>Chand_Software_Block_Product_View</product_view>
</rewrite>
</catalog>
</blocks>
</global>
</config>
(3) Now Create block file of our custom module in app/code/local/Chand/Software/Block/Product/View.php
class Chand_Software_Block_Product_View extends Mage_Catalog_Block_Product_View
{
/**
* Put your logic here
*
*/
}
1 comment:
Thank you for posting this awesome article. I'm a long time reader but I've never actually left a comment.
I've bookmarked your blog and shared this on Facebook.
Many thanks again for a really good post!
Post a Comment