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 .
Không có nhận xét nào:
Đăng nhận xét