Today, Magento Tutorial will show you how to change a basic block of Magento. When you do this kind of modification, it is better to keep in mind one of the basic rules Magento development:
– You can not edit in the files in/app/code/core.
Instead, we will overload this Block, create a class that will extend this core Block and rewrite only the part you want to change. Then, in order to use it, declare your file in our config.xml file (as usual).
1. Start by re-creating a module in your folder Pfay and call it MyProduct
So create the file:
With etc/config.xml and do not forget to declare the Pfay_All.xml (see lesson 2 ).
2. Create your « modified » Block
What interests us is to rewrite the block Mage_Catalog_Block_Product_View. We want to rewrite the method « showInfos » of this Block.
So we will create in /app/code/local/Pfay/MyProduct/Block/Product/file view.php.
Which will contain:
- Class Pfay_MonProduit_Block_Product_View extends Mage_Catalog_Block_Product_View
- public function afficherLesInfos()
- return ‘les infos complementaires’;
3. Tell Magento to take into accounts the new version of this block
Edit the config.xml of your module MyProduct and put in it:
- <?xml version=“1.0”?>
With these tags, we say we will configure a block of Magento’s core called « catalog » and we will rewrite () the « product_view » block of this module. Now it will take our new block to replace the base.
Ready to foster your knowledge with MAGENTO 2 BASIC GUIDE
Is your site still a mess and Magento extensions are not enough to save your site? Save your site with Magento Web Development Services now