Almost people who’ve been working with Magento are very impressive with rewrite feature, one of the most powerful features in this platform. In Magento, rewriting means that developers are allowed to override and extend core Magento functionality. In this post, we will show you the way to rewrite blocks in Magento.
It’s so simple to create a rewrite for a block in your Magento store.
First, you have to define the rewrite in the blocks tag of your config .xml:
This step will help telling Magento that the block Products_view is being written to your custom block MageHit_Foo_Block_Product_View.
Next, you need to create your new block. We recommend you to keep the same structure. In this post, your block will be Foo/Block/Product/View.php.
After that, you declare your block’s class which extends from Mage_Catalog_Blog_Product_View, and doing this gives us access to the all the functions and variables defined in Mage_Catalog_Product_View via inheritance.
Thereby, we are now free to override and extends this block without modifying the core code.
The same process can be applied when rewriting models and helpers as seen below:
–Rewriting the Customer model to our model class which extends the rewritten class
That’s easy, right? Creating a rewrite block is pretty straight forward and can’t difficult for you. If you have any problems, contact us for the help.
Thanks for reading!