In this exercise, we will change the behavior of a block by extending
or inheriting the original class and redefining the behavior
of a specific function or method. Specifically we will
redefine the behavior of function canEmailToFriend().
We want to change the behavior of a class member located in this
file
app\code\core\Mage\Catalog\Block\Product\View.php
Our override will be found here:
app\code\local\Msc\Module9\Block\Catalog\Product\View.php
First we want to create a new module structure. See the first tutorial on modules for more details about this step.
in \app\etc\modules\Msc_Module9.xml
<?xml version="1.0"?> <config> <modules> <Msc_Module9> <active>true</active> <codePool>local</codePool> </Msc_Module9> </modules> </config>
in app\code\local\Msc\Module9\Block\Product\View.php
<?php Class Msc_Module9_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View{ public function canEmailToFriend() { // By returning false, we basically eliminate the block. return false; } }
in app\code\local\Msc\Module9\etc\config.xml
<?xml version="1.0"?> <config> <modules> <Msc_Module9> <version>1.0.0</version> </Msc_Module9> </modules> <global> <blocks> <catalog> <rewrite> <product_view>Msc_Module9_Block_Catalog_Product_View</product_view> </rewrite> </catalog> </blocks> </global> </config>