Friday 10 April 2015

How to override Admin controller Action in Magento

>> Hi! friends this example will help you to override admin controller action. I had to replicate admin product edit section as there were two types of products. First one was normal Magento products another was Used products. Client wanted to manage them separately. So, I override admin product controller action. How ?


 First You need to create a new module. Create a xml file within app/etc/modules/JR_Overridecontroller.xml
                        <?xml version="1.0"?>
                        <config>
                            <modules>
                                <AB_Overridecontroller>
                                    <active>true</active>
                                    <codePool>local</codePool>
                                </AB_Overridecontroller>
                            </modules>
                        </config>




 Now make the config.xml within app/code/local/AB/Overridecontroller/etc/config.xml
                         <?xml version="1.0"?>
                        <config>
                            <modules> 
                               <AB_Overridecontroller> 
                                 <version>1.0.0</version> 
                               </AB_Overridecontroller> 
                             </modules>
                         
                            <admin>
                                <routers>
                                    <adminhtml>
                                        <args>
                                            <modules>
                                                <AB_Overridecontroller before="Mage_Adminhtml">AB_Overridecontroller</AB_Overridecontroller>
                                            </modules>
                                        </args>
                                    </adminhtml>
                                </routers>
                            </admin>
                        </config> 



 So, now make the controller file that you need to modify within app/code/local/AB/Overridecontroller/controllers/Catalog/ProductController.php
                   <?php
                        include_once("Mage/Adminhtml/controllers/Catalog/ProductController.php");
                        class Ab_Overridecontroller_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
                        {
                            public function editAction(){
                               
                                // Here is your overridden controller method.....
                               
                            }
                        }
                    ?>