1、首先在App下创建新的模块,依次创建如下文件:
/app/code/local/App/Shopping
/app/code/local/App/Shopping/etc
/app/code/local/App/Shopping/etc/config.xml
/app/code/local/App/Shopping/controllers
/app/code/local/App/Shopping/controllers/CartController.php
2、编辑/app/code/local/App/Shopping/etc/config.xml文件,加入如下代码:
<?xml version="1.0"?>
<config>
<modules>
<App_Shopping>
<version>0.1.0</version>
</App_Shopping>
</modules>
<global>
<rewrite>
<App_Shopping_cart>
<from><![CDATA[#^/checkout/cart/#]]></from>
<!--
"/App/Shopping/controllers/CartController.php" (?)
-->
<to>/shopping/cart/</to>
</App_Shopping_cart>
</rewrite>
</global>
<frontend>
<routers>
<App_Shopping>
<use>standard</use>
<args>
<module>App_Shopping</module>
<frontName>shopping</frontName>
</args>
</App_Shopping>
</routers>
</frontend>
</config>
3、改写你自己的控制器
/app/code/local/App/Shopping/controllers/CartController.php
请将下面的代码添加到你的控制器中,我们唯一修改的地方是在index动作中添加一个error_log();
# 控制器不会自动加载,所以我们需要包含文件
require_once 'Mage/Checkout/controllers/CartController.php';
class App_Shopping_CartController extends Mage_Checkout_CartController
{
#覆写indexAction方法
public function indexAction()
{
# Just to make sure
error_log('成功重写购物车!');
parent::indexAction();
}
}
4、 新建app/etc/modules/App_All.xml ,激活我们新的Shopping模块
<?xml version="1.0"?>
<config>
<modules>
<App_Shopping>
<active>true</active>
<codePool>local</codePool>
</App_Shopping>
</modules>
</config>