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';
}

}

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

3 thoughts on “Override magento controller

Leave a Reply