Magento Helper Override/Overwrite

magento help override

In this article, we are going to discuss how to simply override existing Magento helper class. Sometimes you need to change the existing functions of the Mage helper classes because they don’t return what you actually want them to return or your want to add extra bit of code in the existing functions.

Let’s try overriding Mage_Checkout_Helper_Cart helper class in this article.

Step 1

Create a module in your local folder applocalScommerceCheckout

Step 2

Register your module in etc/modules directory by creating Scommerce_Checkout.xml file with the following content

<?xml version="1.0"?>
<config> <modules> <Scommerce_Checkout> <active>true</active> <codePool>local</codePool> </Scommerce_Checkout> </modules>
</config>

Step 3

Create config.xml file inside your etc directory under your module directory applocalScommerceCheckoutetcconfig.xml

<?xml version="1.0"?> <config> <modules> <Scommerce_Checkout> <version>0.0.1</version> </Scommerce_Checkout> </modules> <global> <helpers> <checkout> <rewrite> <data>Scommerce_Checkout_Helper_Data</data> </rewrite> </checkout> </helpers> </global> </config>

Step 4

Create Data.php file in helper directory of your module directory applocalScommerceCheckouthelperData.php

<?php class Scommerce_Checkout_Helper_Data extends Mage_Checkout_Helper_Data
{ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage') { return false; } public function newCheckoutHelperFunction() { return 'Overridden checkout helper function' }
}

Step 5

You can call your new helper function in phtml by using the following snippet -:

<?php echo $this->helper('checkout')->newCheckoutHelperFunction();
?>

Discover more from WHO WILL CARE eCommerce

Subscribe now to keep reading and get access to the full archive.

Continue reading