Site icon Qaisar Satti's Blogs

Override magento controller

Override magento controller

Override magento controller

Today, we’ll talk about how to override a magento controller.Every Magento project requires a certain level of customization. This may involve adding a new element or overriding an existing one. For any suggestions & question, please feel free to drop a comment.

First Step:

I am overriding the customer controller. First thing will create new module file.
The file location will me  will be

app/etc/modules/QaisarSatti_Customer.xml

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

Second Step:

We will create module configuration file. So file location will be

app/code/local/QaisarSatti/Customer/etc/config.xml

<?xml version="1.0"?>
    <config>
        <modules>
            <QaisarSatti_Customer>
                <version>0.0.1</version>
            </QaisarSatti_Customer>
        </modules>
        <frontend>
            <routers>
                <customer>
                    <args>
                        <modules>
                            <QaisarSatti_Customer before="Mage_Customer">QaisarSatti_Customer</QaisarSatti_Customer>
                        </modules>
                    </args>
                </customer>
            </routers>
        </frontend>
    </config>

Third Step:

Now we will create the Our controller file.

app/code/local/QaisarSatti/Customer/controllers/AccountController.php

<?php

/**
* Overriding Customer account controller
*/

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

class QaisarSatti_Customer_AccountController extends Mage_Customer_AccountController {

public function ajaxAction() {  //if you want to create a custom method in customer controller
   echo 'Ajax cction is working!!';
}

public function loginAction() {
   echo 'Overring the Login Action is working';
}

}
Exit mobile version