我需要在code/core/Mage/ProductAlert/controllers
的AddController.php
中覆盖stockAction()
。所以我搜索了很多,看看如何继续,得到这个:
/etc/modules/Totem_ProductAlert.xml
<?xml version="1.0"?>
<config>
<modules>
<Totem_ProductAlert>
<active>true</active>
<codepool>local</codepool>
</Totem_ProductAlert>
</modules>
</config>
/code/local/Totem/ProductAlert/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Totem_ProductAlert>
<version>0.0.1</version>
</Totem_ProductAlert>
</modules>
<frontend>
<routers>
<productalert>
<args>
<modules>
<Totem_ProductAlert before="Mage_ProductAlert">Totem_ProductAlert</Totem_ProductAlert>
</modules>
</args>
</productalert>
</routers>
</frontend>
</config>
/code/local/Totem/ProductAlert/controllers/AddController.php
class Totem_ProductAlert_AddController extends Mage_ProductAlert_AddController
{
public function stockAction()
{
Mage::log('test', null, 'Test.log');
}
但是该动作没有被覆盖,并且没有创建Test.log。
谁知道我在哪里搞砸了?
谢谢。
你的代码有问题:
-
Totem_ProductAlert.xml
中的
syntax issue
。<codepool>
应该be<codePool>
.p应为大写字母。
<?xml version="1.0"?>
<config>
<modules>
<Totem_ProductAlert>
<active>true</active>
<codePool>local</codePool>
<depends>Mage_ProductAlert</depends>
</Totem_ProductAlert>
</modules>
</config>
- 要求正确调用Core AddController.php at/ul>
<?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * Description of AddController * * @author work */ require_once Mage::getModuleDir('controllers', 'Mage_ProductAlert').DS.'AddController.php'; class Totem_ProductAlert_AddController extends Mage_ProductAlert_AddController { public function stockAction() { Mage::log('test', null, 'Test.log',true); } }
try this
<?xml version="1.0"?>
<config>
<modules>
<Totem_ProductAlert>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Totem_Custom>
</modules>
</config>
config . xml
<?xml version="1.0"?>
<config>
<modules>
<Totem_ProductAlert>
<version>0.1.0</version>
</Totem_ProductAlert>
</modules>
<frontend>
<routers>
<productalert>
<use>standard</use>
<args>
<module>Totem_ProductAlert</module>
<frontName>productalert</frontName>
</args>
</productalert>
</routers>
</frontend>
<global>
<rewrite>
<totem_productalert_productalert_addcontroller>
<from><![CDATA[#^/productalert/add/#]]></from> <!-- Mage_ProductAlert_AddController -->
<to>/productalert/productalert_add/</to> <!-- Totem_ProductAlert_ProductAlert_AddController -->
</totem_productalert_productalert_addcontroller>
</rewrite>
<helpers>
<productalert>
<class>Totem_ProductAlert_Helper</class>
</productalert>
</helpers>
</global>
<admin>
<routers>
<productalert>
<use>admin</use>
<args>
<module>Totem_ProductAlert</module>
<frontName>admin_productalert</frontName>
</args>
</productalert>
</routers>
</admin>
</config>
控制器 <?php
require_once "Mage/ProductAlert/controllers/AddController.php";
class Totem_ProductAlert_ProductAlert_AddController extends Mage_ProductAlert_AddController{
public function stockAction(){
Mage::log('test', null, 'Test.log');
}
}