checkout/cart

While working in Magento you may sometimes run into situations where you would like to override the functionality of the Magento core controllers. But you cannot edit the core controllers of Magento as it will hinder you from upgrading your Magento version. So we have to find a simple solution for that. Don’t worry, today we will see how to override Magento core controllers.For this, you have to create a custom module. If you do not know how to create a custom module, then read this post. Now suppose we want to override thecontroller. To do this, we will have to edit just two files in our custom module.Suppose our custom module is present in the namespaceand our module is named as



Step 1:

Open the appcodelocalCompanyWebetcconfig.xml and edit it as follows:

The name of the core module to be overridden is written in between the router tags. Here we want to override the checkout module so checkout is to be wrapped in <routers> tags.

After that we will tell Magento to call our custom module before the Mage/Checkout module

<?xml version="1.0" encoding="UTF-8"?>

<config>

<modules>

<Company_Web>

<version>0.0.1</version>

</Company_Web>

</modules>

<frontend>

<routers>

<checkout><!-- Name of core module to be overridden -->

<args>

<modules>

<Company_Web before="Mage_Checkout">Company_Web</Company_Web><!-- Tell Magento to call our custom module before the Mage/Checkout module -->

</modules>

</args>

</checkout>

</routers>

</frontend>

</config>



Step 2:

Now create the controller file to be overridden, CartController.php in our case. (appcodelocalCompanyWebcontrollersCartController.php)

<?php

/**

* Magento

*

* Override Mage_Checkout_Cart controller

*/





/**

* IMPORTANT

* Include the core file to be overridden

*/

require_once("Mage/Checkout/controllers/CartController.php");



/**

* IMPORTANT

* Extend the core controller in our custom controller.

*/

class Company_Web_CartController extends Mage_Checkout_CartController

{

/**

* Get current active quote instance

*

* @return Mage_Sales_Model_Quote

*/

public function indexAction()

{

echo "This controller has been overridden.";

}

}



And you are done now. Override what you want:)