Override Magento Admin Controller

March 31st, 2012 by Laeeq | 3 comments

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.

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

  1. <?xml version=“1.0″?>
  2. <config>
  3. <modules>
  4. <Justwebdevelopment_Overridecontroller>
  5. <active>true</active>
  6. <codePool>local</codePool>
  7. </Justwebdevelopment_Overridecontroller>
  8. </modules>
  9. </config>

Step 2: Make config.xml from

app/code/local/Justwebdevelopment/Overridecontroller/etc/config.xml

  1. <?xml version=“1.0″?>
  2. <config>
  3. <modules>
  4. <Justwebdevelopment_Overridecontroller>
  5. <version>0.0.1</version>
  6. </Justwebdevelopment_Overridecontroller>
  7. </modules>
  8. <admin>
  9. <routers>
  10. <adminhtml>
  11. <args>
  12. <modules>
  13. <Justwebdevelopment_Overridecontroller before=“Mage_Adminhtml”>Justwebdevelopment_Overridecontroller</Justwebdevelopment_Overridecontroller>
  14. </modules>
  15. </args>
  16. </adminhtml>
  17. </routers>
  18. </admin>
  19. </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.

  1. <?php
  2. include_once(“Mage/Adminhtml/controllers/Catalog/ProductController.php”);
  3. class Justwebdevelopment_Overridecontroller_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
  4. {
  5. public function editAction(){
  6. echo “Override Product Edit Action…”;exit;
  7. }
  8. }
  9. ?>

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.

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • Get an array of billing addresses and shipping addresses in Magento
  • Duplicate Data Issue with Custom Magento Collection
  • Tips To Improve Your Ecommerce Site’s Security
  • Magento: Display New Products from Specific Category On Home Page
  • Dealing with Magento Model or Collections
  • Magento: Display New Products On Home Page
  • Magento: Display More Than 5 New Products
  • Override Controllers in Magento
  • Improve the performance of your Magento store
  • Magento Released Community Edition 1.7.0.1
  • Write custom title, keywords and description in Magento module
  • Moving Magento site from development to live server
  • Display Related products on product details page in Magento
  • Magento – Models, resource models, and collections
  • Magento – Add thumbnail images to Magento admin grid
  • Simple url rewrite in magento
  • Generate CSV file in Magento
  • Resize image in Magento using Varien_Image class
  • AJAX requests in Magento
  • Category Navigation Listings in Magento
  •  

     

    1. April 16th, 2012 at 09:32 | #1

      Nice article but I don’t urdnnstaed whether you’re just showing how to add translations to a custom module or a custom module that you add translations to for ALL custom modules? If it is the latter, doesn’t this break the modularity of modules? If you want to re-use a module on another site you would have to copy over the extra translations module.Also, I think codepool should be codePool.Nice article though, I read your site a lot.

    2. August 15th, 2012 at 15:09 | #2

      Thanks this is so simple after read your post.
      I found the best guideline here.
      Thanks for give me.

    3. abigailhooverrz
      October 3rd, 2012 at 15:39 | #3

      Someone essentially lend a hand to make seriously articles I might state. That is the first time I frequented your website page and up to now? I surprised with the analysis you made to make this particular put up incredible. Great job!

    1. No trackbacks yet.