How to override a core controller in the magento

How to Override a core controoler in magento ?? Magento controller class override is something different then others classes. Controller override is not same as model, helper, block override. I found lot of thread on magento forum , but not working for me (1.3.2.x),  few hours debug, I got it .so how ? a example  is override the ProductControoler ( I already create a module call Webcaker_Catalog),steps for override Step1 : add xml config to confg.xml





standard

Webcaker_Catalog
catalog






...

  
  #^/catalog/product/#
    /catalog/product/
  



Note: for from node, need use CDATA to warp it . Step2 : add new file ProductControler.php in the controllers in Webcaker/Catalog with code below

//important! Magento cannot load the ProductController automatically
require_once 'require_once 'Mage/Catalog/controllers/ProductController.php';
class Webcaker_Catalog_ProductController extends Mage_Catalog_ProductController
{
public function viewAction()
{
//your logic here
}
}

done , magento rock!

About caker

Welcome to WebCaker. My name is Zhang tongzhu( Nickname : Caker) . I'm 30-year-old, currently working as full time PHP web application developer and learn the iPhone development at same time.
This entry was posted in Magento and tagged , , . Bookmark the permalink.

7 Responses to How to override a core controller in the magento

  1. Bartosz says:

    Big thx man! It’s works great.

    Could You write some more explanation about this lines: 16. 17. 18. #^/catalog/product/# 19. /catalog/product/ 20. 21.

    Usual You must to write what do You want to rewrite For example:

    MyClientCompany_Catalog_Block_Product_List

    I put node between because I want to rewrite block… In your example node in between . In the same level as . Is this mean that I want to rewrite controller, when I put rewrite node as child of ?

    This notation:

    ^/catalog/product/

    /catalog/product/ is also a little strange for me.

    Once again, thanks for this post Best regards from Poland

  2. caker says:

    hi Bartosz, I’m happy it’s useful for you, if you wanna override a block, you can do by this :

    ...
    
          
            
    Webcaker_Catalog_Block_Product_View_Filter
              Webcaker_Catalog_Block_Product_View
            
          
        
    ...
    

    not sure it’s right magento’s way..

  3. Nacho says:

    great!!!!! It’s the only Magento controller override works 4me!!!

    thanks a lot! easy and neat!

    caker, I’ll give u the source code of the world!

    Nacho

  4. Neo says:

    nice tutorial but it didn't worked for me i am using version 1.4.0.1

  5. Neo says:

    Can you please upload the module files here?

  6. Neo says:

    and where is the etc/module/Namespace_modulename.xml file

  7. Robert says:

    Hi

    It didn’t work for me.

    …Buuut i think that i did something wrong.

    Can you upload in an one-all package? (xml, php , folders, etc)

    Thanks, Robert.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>