Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Overriding customer account controller

Tags:

magento

Hi I'm trying to override Mage_Customer_AccountController, so that I can extend the createPostAction method. For the life of me I can't seem to do this, it either throws a 404 page, which suggests that its not the right path for the file or it defaults to orignal.

<rewrite>
       <company_modulename_account>
           <from><![CDATA[#^/customer/account/#]]></from>
           <to>/modulename/account</to>
       </company_modulename_account>
</rewrite>

My controller is located here local/company/modulename/controllers/AccountController.php

like image 427
jamessy Avatar asked Feb 19 '12 14:02

jamessy


People also ask

How do you override a controller?

To override a controller, you have to create a subclass to define existing functions. Now select a function from the controller for overriding from the addons. For better understanding, I have selected the following Carousel Recently viewed function for overriding.


1 Answers

Instead, you can try as:

...   
 <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <company_modulename before="Mage_Customer">Company_Modulename</company_modulename>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
...

And create a controller class:
app/code/[codePool]/Company/Modulename/controllers/AccountController.php
with the following code:

require_once 'Mage/Customer/controllers/AccountController.php';
class Company_Modulename_AccountController extends Mage_Customer_AccountController
{
    public function createPostAction(){
        die('Overriden');
    } 
}

Here is more info about controller overriding:
https://stackoverflow.com/a/7117076/887385

Good Luck!!

like image 61
3 revs Avatar answered Oct 03 '22 08:10

3 revs