Laila
Laila

Reputation: 1501

Override several controllers in one single module Magento

I need to override the following controllers

app/code/core/Mage/Customer/controllers/AccountController.php 
app/code/core/Mage/Customer/controllers/AddressController.php
app/code/core/Mage/Sales/controllers/OrderController.php 

In one single module that overrides the native checkout of Magento. Following's Inchoo's tutorial, I did this in my config.xml :

<frontend>
    <routers>
        <checkout>
            <args>
                <modules>
                    <mycompany_checkout before="Mage_Checkout">MyCompany_Checkout</mycompany_checkout>
                </modules>
            </args>
        </checkout>
        <customer>
            <args>
                <modules>
                    <mycompany_checkout before="Mage_Customer">MyCompany_Checkout_AddressController</mycompany_checkout>
                </modules>
            </args>
        </customer>
    </routers>
</frontend>

And the code of my controller (Example of AddressController)

require_once(Mage::getModuleDir('controllers','Mage_Customer').DS.'AddressController.php');


class MyCompany_Customer_AddressController extends Mage_Customer_AddressController {
 // Overriden function ...
}

but it's not working.

Any clue on what I'm missing ?

Upvotes: 1

Views: 991

Answers (1)

Rabea
Rabea

Reputation: 2024

Here is an extension I wrote as an example. it has been tested and working on all controllers overridden.

config.xml

<?xml version="1.0" ?>
<config>
        <modules>
                <Rabee3_Stackoverflow>
                        <version>1.0.0</version>
                </Rabee3_Stackoverflow>
        </modules>
<frontend>
    <routers>
        <sales>
            <args>
                <modules>
                    <stackoverflow before="Mage_Sales">Rabee3_Stackoverflow</stackoverflow>
                </modules>
            </args>
        </sales>
        <customer>
            <args>
                <modules>
                    <stackoverflow before="Mage_Customer">Rabee3_Stackoverflow</stackoverflow>
                </modules>
            </args>
        </customer>
    </routers>
</frontend>
</config>

Controllers to override, showing the required core file and also how it is extended:

AccountController.php

require_once(Mage::getModuleDir('controllers','Mage_Customer').DS.'AccountController.php');
class Rabee3_Stackoverflow_AccountController extends Mage_Customer_AccountController
{

AddressController.php

require_once(Mage::getModuleDir('controllers','Mage_Customer').DS.'AddressController.php');
class Rabee3_Stackoverflow_AddressController extends Mage_Customer_AddressController
{

OrderController.php

require_once(Mage::getModuleDir('controllers','Mage_Sales').DS.'OrderController.php');
class Rabee3_Stackoverflow_OrderController extends Mage_Sales_OrderController
{

I hope that this helps.

Upvotes: 2

Related Questions