Override Magento Admin Controller

Home / Magento / Override Magento Admin Controller

When you use magento sometime need to customize some admin core functionality based on requirement. If you want to change core functionality of any controller so you need to override controller action with your controller action. Learning how to perform this action may be
helpful to those who have computer forensics degrees.

how to override magento admin controller action

This example to show you override edit action from ProductController.php is located app/code/core/Mage/Adminhtml/controllers/Catalog

Step 1: Create new module from app/etc/Justwebdevelopment_Overridecontroller.xml

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

Step 2: Make config.xml from app/code/local/Justwebdevelopment/Overridecontroller/etc/config.xml

<?xml version="1.0"?>
<config>

	<modules>  
	   <Justwebdevelopment_Overridecontroller>  
		 <version>0.0.1</version>  
	   </Justwebdevelopment_Overridecontroller>  
	 </modules>
 
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Justwebdevelopment_Overridecontroller before="Mage_Adminhtml">Justwebdevelopment_Overridecontroller</Justwebdevelopment_Overridecontroller>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
	
</config>

Using above code you want to override any action from any adminhtml controller. Only you need to make controller file for that.
Here I want to give example of ProductController.php file.

Step 3: Make controller file from app/code/local/Justwebdevelopment/Overridecontroller/controllers/Catalog/ProductController.php
And first include your default controller calss file then write new controller class for update then extends your new controller file to your default controller class like here extends with “Mage_Adminhtml_Catalog_ProductController”. After the define those action whcih you want to override.

<?php
include_once("Mage/Adminhtml/controllers/Catalog/ProductController.php");
class Justwebdevelopment_Overridecontroller_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
	public function editAction(){
		echo "Override Product Edit Action...";exit;
	}
}
?>

If you follow all three steps above then when you try to edit any products from backend then it shows this message “Override Product Edit Action…”. Please be careful with module name and controller name.

Hopefully this information is helpful to override magento adminhtml controllers.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *