Let's talk Contact us. No cost. No obligation.

Fill out this form and we will contact you with in 24 hrs.

    captcha

     

    Knowledge Base

    How to Override controller in magento / Override controller’s action in magento

    April 21, 2014

    Requirement: Sometimes you may run into situation where you want to override the core functionality of Magento core controllers. So in this case, the best practice is override the controller then override actions or add new actions for custom requirement.

    For example you want to override OnepageController.php file and override indexAction.
    In this example my custom module namespace is “Onsis” and I am going to override indexAction Mage_Checkout_OnepageController

    Base File Path :

    app/code/core/Mage/Checkout/controllers/OnepageController.php

    To Do the same we have to follow bellow steps.

    Step1: We need to create a custom module

    File Path : app/etc/modules/
    File Name: Onsis_Checkout.xml
    File Content:
    true
    local

    Step2: Now we have to create bellow files in our custom module

    File Path: app/code/local/Onsis/Checkout/etc/config.xml

    Below is content for config.xml file

    0.0.1

    Onsis_Checkout
    Below is content for OnepageController.php
    File Path : app/code/local/Onsis/Checkout/controllers/OnepageController.php
    /* Description: Override OnepageController.php file
    * Overwride indexAction
    * Author: Pramod Gupta
    */
    require_once ‘Mage/Checkout/controllers/OnepageController.php’;
    class Onsis_Checkout_OnepageController extends
    Mage_Checkout_OnepageController {
    public function indexAction()
    {
    echo “Great! You are in onsis checkout controller section”;
    exit;
    }
    }