How to Override a Controller in Adminhtml in Magento 1.7

adminhtmlcontrollersmagento-1.7

Currently I'm trying to override the GroupController of Mage_Adminhtml_Customer so I can add some code for saving my custom field in the Customer Groups menu. As you can think it doesn't really work as I want what means that it seems that my controller is ignored by Magento so far but I don't get the mistake I've made. Here are the snippets:

<?xml version="1.0" ?>
<config>
    [...]
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Mynamespace_CustomerGroupReturnable before="Mage_Adminhtml">Mynamespace_CustomerGroupReturnable</Mynamespace_CustomerGroupReturnable>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

And the controller:

require_once 'Mage/Adminhtml/Customer/controllers/GroupController.php';

class Mynamespace_CustomerGroupReturnable_GroupController extends Mage_Adminhtml_Customer_GroupController
{
    public function saveAction()
    {
        die(':D'); //just for testing
    }
}

Can anybody see what's missing? Thanks!

Best Answer

Put your controller file under an Admintml folder. Better to use a similar folder path of the class which you are going to override.

config.xml

<?xml version="1.0" ?>
<config>
    [...]
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Mynamespace_CustomerGroupReturnable before="Mage_Adminhtml">Mynamespace_CustomerGroupReturnable_Adminhtml</Mynamespace_CustomerGroupReturnable>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

Controller file :

require_once 'Mage/Adminhtml/controllers/Customer/GroupController.php';

class Mynamespace_CustomerGroupReturnable_Adminhtml_GroupController extends Mage_Adminhtml_Customer_GroupController
{
    public function saveAction()
    {
        die(':D'); //just for testing
    }
}
Related Topic