magento 如何重写结帐社区控制器

magento how to rewrite checkout community controller

我已经尝试从社区扩展覆盖结帐控制器 2 个小时了,但仍然无法正常工作。

我的自定义模块已激活。 尝试重写 (Community/Manv/Ajaxcoupon/controllers/Indexcontroller.php) 这是我的控制器。

require_once 'Manv/Ajaxcoupon/controllers/IndexController.php';

    class Name_Promocode_CartController extends Manv_Ajaxcoupon_IndexController
    {

        public function customcouponPostAction(){
            die('custom');
        }

        public function couponPostAction()
        {
            die('We are in');
    }

这是我的config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Name_Promocode>
            <version>1.0.0</version>
        </Name_Promocode>
    </modules>
    <frontend>
        <routers>
          <checkout>
            <args>
              <modules>
                <Name_Promocode before="Manv_Ajaxcoupon">Name_Promocode</Name_Promocode>
              </modules>
            </args>
          </checkout>
        </routers>
    </frontend>
</config>

已删除缓存... 找不到问题所在,当我在社区模块中放置一个 die() 时,我看到了。但似乎我的模块没有覆盖任何东西。

// 尝试与下面的 config.xml 代码进行比较。

<config>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <name_promocode before="Mage_Tag">Manv_Ajaxcoupon</name_promocode>
                    </modules>
                </args>
            </tag>
        </routers>
    </frontend>
</config>

//备用覆盖控制器代码。

  <global>
        <!-- This rewrite rule could be added to the database instead -->
        <rewrite>
            <!-- This is an identifier for your rewrite that should be unique -->
            <!-- THIS IS THE CLASSNAME IN YOUR OWN CONTROLLER -->
            <customcontactsunique>
                <from><![CDATA[#^/contacts/index/#]]></from>
                <!--
                    - mymodule matches the router frontname below
                    -  matches the path to your controller

                    Considering the router below, "/customcontacts/index/" will be
                    "translated" to "app/code/local/Amit/Customcontacts/controllers/IndexController.php" (?)
                -->
                <to>/customcontacts/index/</to>
            </customcontactsunique>
        </rewrite>
    </global>

//比较控制器代码。

    require_once(Mage::getModuleDir('controllers','Manv_Ajaxcoupon').DS.'IndexController.php');

class Name_Promocode_CartController extends Manv_Ajaxcoupon_IndexController
{
  // some code
}

More reference

Alternate override controller link

试试这个:

<config>
    <modules>
        <Name_Promocode>
            <version>1.0.0</version>
        </Name_Promocode>
    </modules>
    <frontend>
        <routers>
          <name_promocode>
                <use>standard</use>
                <args>
                    <module>Name_Promocode</module>
                    <frontName>promocode</frontName>
                </args>
          </name_promocode>
        </routers>
    </frontend>
    <global>
        <rewrite>
            <name_promocode> 
                <from><![CDATA[#^/ajaxcoupon/index/#]]></from>  <!-- the URL which u want to override-->
                <to>/promocode/cart/</to>  <!-- destination url -->
            </name_promocode>
        </rewrite>
    </global>
</config>

终于让它适用于这个config.xml

<config>
    <modules>
        <Name_Promocode>
            <version>1.0.0</version>
        </Name_Promocode>
    </modules>
    <frontend>
        <routers>
          <name_promocode>
                <use>standard</use>
                <args>
                    <module>Name_Promocode</module>
                    <frontName>promocode</frontName>
                </args>
          </name_promocode>
        </routers>
    </frontend>
    <global>
        <rewrite>
            <name_promocode> 
                <from><![CDATA[#^/ajaxcoupon/index/#]]></from>  <!-- the URL which u want to override-->
                <to>/promocode/cart/</to>  <!-- destination url -->
            </name_promocode>
        </rewrite>
    </global>
</config>

希望这会对某人有所帮助:D