saturno
saturno

Reputation: 43

Extend magento core controller (Checkout/OnepageController)

I am having problems while overriding a core controller. I want to add a new function but it only works if I do it in the core file (code/core/checkout/controllers/onepagecontroller.php).

I have followed some post, but it's not working. Some of them are:

(I can't add more links, sorry)

I don't know what is happening... maybe you can help me ;).

I'm using magento 1.5 and I have this 3 files:


local -> Arias -> CoreExtended -> etc -> config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Arias_CoreExtended>
            <version>0.1.0</version>
        </Arias_CoreExtended>
    </modules>

    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <Arias_CoreExtended before="Mage_Checkout">Arias_CoreExtended_Checkout</Arias_CoreExtended>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

app -> etc -> modules -> Arias_CoreExtended.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Arias_CoreExtended>
            <active>true</active>
            <codepool>local</codepool>
        </Arias_CoreExtended>
    </modules>
</config>

local -> Arias -> CoreExtended -> controllers -> Checkout -> OnepageController.php

<?php

require_once 'Mage/Checkout/controllers/OnepageController.php';

class Arias_CoreExtended_Checkout_OnepageController extends Mage_Checkout_OnepageController
{
    public function collectAction()
    {
        echo 'WTF?';
    }

    public function indexAction()
    {
        echo "This controller has been overridden.";
    }
}

Thanks in advance for your time, regards.

Upvotes: 3

Views: 4885

Answers (3)

bukart
bukart

Reputation: 4906

Your approach is mostly correct @satumo. The only thing you should change is this line

<Arias_CoreExtended before="Mage_Checkout">Arias_CoreExtended</Arias_CoreExtended>

So your full configuration have to look like this:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Arias_CoreExtended>
            <version>0.1.0</version>
        </Arias_CoreExtended>
    </modules>  

    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <Arias_CoreExtended before="Mage_Checkout">Arias_CoreExtended</Arias_CoreExtended>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

Upvotes: 0

Kus
Kus

Reputation: 2537

I would first mirror the same directory structure of the controller you are overwriting, so in this case change: local/Arias/CoreExtended/controllers/Checkout/OnepageController.php to local/Arias/CoreExtended/controllers/OnepageController.php

You should lowercase your namespace/module name and you need to remove _Checkout as it is overwriting the controllers in general, and will look up any that exist in the module to use them instead if not fall back to standard. The correct code would be:

<arias_coreextended before="Mage_Checkout">Arias_CoreExtended</arias_coreextended>

I have used this exact setup with success to overwrite the Onepage controller!

Upvotes: 1

B00MER
B00MER

Reputation: 5491

I would try lower casing your namespace/modulename like so:

<arias_coreextended before="Mage_Checkout">Arias_CoreExtended_Checkout</arias_coreextended>

Upvotes: 0

Related Questions