Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

How to override ResultController of CatalogSearch action in magento


If you want to override your ResultController action of CatalogSearch module in your local than follow the following easy steps.

Step1: Create xml file in app/etc/modules

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

Step2: Create controller file in app/code/local/HK/Compare/controllers

ResultController.php

Add following code in this .php file

include_once("Mage/CatalogSearch/controllers/ResultController.php");
class HK_Compare_ResultController extends Mage_Core_Controller_Front_Action
{
       public function indexAction()
       {
               echo "Module is comming from local"; //make sure changes working
       }
}

Step3: Create config.xml in app/code/local/HK/Compare/etc
<?xml version="1.0"?>
<config>
    <modules>
        <HK_Compare>
            <version>0.1.0</version>
        </HK_Compare>
    </modules>
    <frontend>
        <routers>
            <catalogsearch>
                <args>
                    <modules>
                        <company_modulename before="Mage_CatalogSearch">HK_Compare</company_modulename>
                    </modules>
                </args>
            </catalogsearch>
        </routers>
        <layout>
            <updates>
                <compare>
                    <file>compare.xml</file>
                </compare>
            </updates>
        </layout>
    </frontend>    
</config>

After this clear your magento cache and test your new changes. Hit like or leave comment if post is helpful for you.

Please support us, Like us on Facebook.

  1. You need to extend Mage_CatalogSearch_ResultController in the place of Mage_Core_Controller_Front_Action
    This is basic rule for extending any controller in Magento, i.e to inherit that particular controller whose functionality is being extended.

    ReplyDelete

 

Copyright @ 2017 HKBlog.