First of all, the Answer here is very helpful: Overriding a Magento Controller in community extention

However, despite passing both of the "tests" mentioned in the answer there, I still have a module controller override that just refuses to work. Here is what I have:

\app\code\local\Company\OnepageCheckout\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Company_OnepageCheckout>
            <version>0.0.1</version> 
        </Company_OnepageCheckout>
    </modules>
    <frontend>
        <routers>
            <onepagecheckout>
                <args>
                    <modules>
                        <company_onepagecheckout before="IWD_OnepageCheckout">Company_OnepageCheckout</company_onepagecheckout>
                    </modules>
                </args>
            </onepagecheckout>
        </routers>
    </frontend>
</config>

\app\code\local\Company\OnepageCheckout\controllers\IndexController.php

<?php

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

class Company_OnepageCheckout_IndexController extends IWD_OnepageCheckout_IndexController
{
    function indexAction() {
        die('Hello world!');
    }
}

\app\etc\modules\Company_OnepageCheckout.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Company_OnepageCheckout>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <IWD_OnepageCheckout />
            </depends>
        </Company_OnepageCheckout>
    </modules>
</config>

This module is meant to override a module that is located in \app\code\community\IWD\OnepageCheckout\[...]

As mentioned at the top of this post, I've used the Reflection class as suggested in that other Question and can see my module first in the array ahead of the community module. However, when I visit mysite.com/onepagecheckout I still see the community module, and can't get it to use my file.

My hunch here is that it might have something to do with the capitalization of the module name that I'm just missing.

有帮助吗?

解决方案

Just change

<company_onepagecheckout before="IWD_OnepageCheckout">Company_OnepageCheckout</company_onepagecheckout> 

to

<Company_OnepageCheckout before="IWD_OnepageCheckout">Company_OnepageCheckout</Company_OnepageCheckout>

If it is not working then used

<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 -->
            <mynamespace_mymodule_onepage_iwd>
                <from><![CDATA[#^/onepagecheckout/index/#]]></from>
                <!--
                    - mymodule matches the router frontname below
                    - checkout_cart matches the path to your controller

                    Considering the router below, "/mymodule/checkout_car/" will be
                    "translated" to "/MyNameSpace/MyModule/controllers/Checkout/CartController.php" (?)
                -->
                <to>/comonepagecheckout/index/</to>
            </mynamespace_mymodule_onepage_iwd>
        </rewrite>
    </global>
<frontend>
        <routers>
            <comonepagecheckout>
                <!-- should be set to "admin" when overloading admin stuff (?) -->
                <use>standard</use>
                <args>
                    <module>Company_OnepageCheckout</module>
                    <!-- This is used when "catching" the rewrite above -->
                    <frontName>comonepagecheckout</frontName>
                </args>
            </comonepagecheckout>
        </routers>
    </frontend>

See more at

其他提示

Your best bet is to drop some debugging code into the standard router (temporarily, of course).

#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
protected function _validateControllerClassName($realModule, $controller)
{
    $controllerFileName = $this->getControllerFileName($realModule, $controller);
    if (!$this->validateControllerFileName($controllerFileName)) {
        return false;
    }

    $controllerClassName = $this->getControllerClassName($realModule, $controller);
    if (!$controllerClassName) {
        return false;
    }

    // include controller file if needed
    if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
        return false;
    }

    return $controllerClassName;
}

Each return false is an instance where the router considers a configured controller and rejects it based on an improper name, not being able to find or include the file, etc.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top