Magento: Overriding a Controller

You can override a controller in Magento in following way.
Steps to override a controller in Magento:
1) When we override the controller in the module, we should not change the core controller files directly. To do this, we add following xml in config.xml inside our custom module:
<config>
<frontend>
<routers>
<checkout>
<args>
<modules>
<mynamespace_checkout before="Mage_Checkout">Mynamespace_Checkout</mynamespace_checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>

2) We create a new custom class in our controllers folder in our custom module.
For Controller to be overrided: app/code/local/Mynamespace/Checkout/controllers/CartController.php
<?php
require_once(Mage::getModuleDir('controllers','Mynamespace_Checkout').DS.'CartController.php');
class Mynamespace_Checkout_CartController extends Mage_Checkout_CartController
{
// your code logic to be implemented here
}
Thats's it! You have your overrided controller.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s