3

I've been pulling my hair out with this... I've looked at probably 20 different tutorials and StackOverflow posts and I can NOT see what is wrong with my code.

I'm trying to override CartController.php

Here is my config file:

<config>
    <modules>
        <OneGiant_CartRedirect>
            <version>1.0.0</version>
        </OneGiant_CartRedirect>
    </modules>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <OneGiant_CartRedirect before="Mage_Checkout">OneGiant_Checkout</OneGiant_CartRedirect>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

Here is my CartController.php

<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class OneGiant_Checkout_CartController extends Mage_Checkout_CartController
{
    protected function _goBack()
    {
        throw new Mage_Exception('Its working!!!!');
        return $this;
    }
}

Here is my OneGiant_CartRedirect.xml

<?xml version="1.0"?>
<config>
    <modules>
        <OneGiant_CartRedirect>
            <active>true</active>
            <codePool>local</codePool>
            <version>1.0.0</version>
        </OneGiant_CartRedirect>
    </modules>
</config>

Here are the file locations:

app/code/local/OneGiant/CartRedirect/etc/config.xml
app/code/local/OneGiant/CartRedirect/controllers/CartController.php
app/etc/modules/OneGiant_CartRedirect.xml

Please any help would be great. None of the log files are showing any related errors or warnings.

1

Please change your config.xml file from this

 <routers>
            <checkout>
                <args>
                    <modules>
                        <OneGiant_CartRedirect before="Mage_Checkout">OneGiant_Checkout</OneGiant_CartRedirect>
                    </modules>
                </args>
            </checkout>
        </routers>

to

 <routers>
            <checkout>
                <args>
                    <modules>
                        <OneGiant_CartRedirect before="Mage_Checkout">OneGiant_CartRedirect</OneGiant_CartRedirect>
                    </modules>
                </args>
            </checkout>
        </routers>

And finally change the name of the controller from

class OneGiant_Checkout_CartController extends Mage_Checkout_CartController

to

class OneGiant_CartRedirect_CartController extends Mage_Checkout_CartController

Your file locations are fine

  • This was it! Thanks so much. So why is that naming convention important? Is that the file location? – Removal Oct 22 '15 at 23:06
5

There are myriad things that could be preventing your override. The quickest way to get to the bottom of this is some debugging code in the _validateControllerClassName method.

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

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

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

    return $controllerClassName;
}

With the above var_dumps in place, you should be able to tell which check your controller failed, which will point to your error.

If your controller doesn't show up in the var_dumps, it means Magento isn't loading your module configuration, which should open up a new path of debugging.

Also -- don't forget to enabled "developer mode" and set the display_errors ini setting to true in index.php.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.