The Following Tutorial will Shows How to override cart controller Add Action or Index Action
First you need to give your Module name and Name_space ,I have taken Anjan as Namespace and override as Modulename
Now Create your module folders and files like below Instruction
1. Magento/app/code/local/Anjan/Override/etc/config.xml
2. Magento/app/code/local/Anjan/Override/controllers/CartController.php
3. Magento/app/etc/modules/Anjan_Override.xml
In config.xml Write the Foloowing code
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Anjan_Override> <!--Change Anjan To Your Module NameSpace and Override to Your Module name-->
<version>0.1.0</version>
</Anjan_Override>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Anjan_Override before="Mage_Checkout">Anjan_Override</Anjan_Override><!--Change Anjan To Your Module NameSpace and Override to Your Module name-->
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
In CartController.php write the following code
<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Anjan_Override_CartController extends Mage_Checkout_CartController
{
public function addAction()
{
echo 'I successfully Override Cart Controller';
parent::addAction();
}
public function indexAction()
{
echo 'I successfully Override Cart Controller';
parent::addAction();
}
}
?>
In Anjan_Override.xml write the following code
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Anjan_Override>
<active>true</active>
<codePool>local</codePool>
</Anjan_Override>
</modules>
</config>
Now upload these files into your server,refresh your cache , the click on Add to cart button you can see the message is displaying . You can use die() statement to make sure whether is overrides or not .
Hi,
ReplyDeleteI had created all these files with the same example that you have given like "Anjan_Override".. but this is not working... any suggestion..?
worked for me!
DeletePlease Clear your cache , As I have worked on it several times and it works always, Please check may be you have missed out something
ReplyDeleteGot it.. after clearing cache it works well..
ReplyDeleteThanks for your script...
Balan
xml code is truncated above.. pls suggest me..
ReplyDeleteUse `Compare` instead of `Checkout` may it work
ReplyDeleteI tried to do this with the Mage_Adminhtml_Catalog Product Controller, but it's not picking my module up. Here is my config.xml
ReplyDeleteSttl_Upermission_Catalog
it helps me a lot. A big thank you for sharing.
ReplyDeleteThat was helpful. Thank you very much!
ReplyDeleteDidn't work for me. Double checked everything :(
ReplyDeleteDid you cleared your cache? because it worked for everyone. May be you missed out something.
DeleteIt will definately dont work,unless you put a file in mymodule.xml in app/design/mymodule/mytheme/layout/
ReplyDeleteIt's helpful for me. Thank u so much
ReplyDeleteWorks great! Thanks!
ReplyDeleteThank You! It helped me a lot...
ReplyDeleteI was getting infinite redirect loop error at first. But on commenting "parent::addAction();" in CartController.php its ok.
I had created all these files with the same example that you have given like "Anjan_Override".. but this is not working... any suggestion..?
ReplyDeleteand Clear your cache again & again
Please help me
Have yo create xml file in app/etc/modules/Anjan_override.xml , I have not mentioned in this article
Deleteyes i have create app/etc/modules/Anjan_override.xml
Deleteand local/Anjan/Override/controllers/CartController.php
local/Anjan/Override/etc/config.xml
yes i have create a etc/modules/Anjan_override.xml
ReplyDeleteand controller
local/Anjan/Override/controllers/CartController.php
config.xml
local/Anjan/Override/etc/config.xml
I have remove cache and i have implement after 6 month's it's working but today I am totally confused what are the issue
controller
config xml
0.1.0
Anjan_Override
etc/module/
true
local
Please help me
The problem is probably here:
DeleteCLASS
After where you define the class make sure you do not have an enter before
They must be touching no spaces
This comment has been removed by the author.
ReplyDeleteRename errors/local.xml.sample to local.xml and check what is the error
Delete