B-219 Sec-55 Noida, India

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

Some times you may run into situation where you want to override the core functionality of Magento core controllers.

So in this case, The best practise is override the controller then override actions or add new actions for custom requirement.

For example you want to override OnepageController.php file and overwride indexAction.

In this example my custom module name space is “MyBlog” and i am going to overwride indexAction


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: MyBlog_Checkout.xml
File Content:

<?xml version=”1.0″?>
Step2: Now we have to create bellow files in our custom module

File Path: app/code/local/MyBlog/Checkout/etc/config.xml
Bellow is content for config.xml file

<?xml version=”1.0″?>
<MyBlog_Checkout before=”Mage_Checkout”>MyBlog_Checkout</MyBlog_Checkout>
Bellow is content for OnepageController.php

File Path : app/code/local/MyBlog/Checkout/controllers/OnepageController.php

require_once ‘Mage/Checkout/controllers/OnepageController.php’;

class MyBlog_Checkout_OnepageController extends Mage_Checkout_OnepageController {

public function indexAction()
echo “Great! You are in MyBlog checkout controller section”;

(Visited 83 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.