Question

How can I disable advanced search feature in Magento?

Even you remove the links from frontend using layouts, if someone who knows Magento URL's accesses /catalogsearch/advanced will get the Advanced Search page.

I discovered some visitors are accessing catalogsearch/advanced/ directly. Why they are doing this? I found that using Advanced Search feature can provide to your competition, very easy and fast, information about how many products you have enabled from each brand/category/in total.

For example in Advanced Search just search for price between 0 and 1000000 and you will get for sure all products as number. Search for all manufacturers and you will get the number of all products in your store too. In my opinion this should be protected. In this case Advanced Search feature should be used but with precaution.

Back to main question how to Enable/Disable Advanced Search for the issue I mentioned above. First I was thinking to rewrite a rule for /catalogsearch/avanced link. The redirect page could have a pretty nice banner.

Thank you.

Was it helpful?

Solution

If you want to remove the links you can via the Layout XML:

<layout version="0.1.0">
    <default>
        <reference name="footer_links">
             <!-- Remove 'Advanced Search' -->
            <action method="removeLinkByUrl"><url helper="catalogsearch/getAdvancedSearchUrl" /></action>
    </reference>
 </default>
</layout>

To disable the controller itself (while not the cleanest approach is the quickest) create a copy of:

app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php

Into the local code pool app/code/local/Mage/CatalogSearch/controllers/AdvancedController.php

And overwrite the local copy to:

class Mage_CatalogSearch_AdvancedController extends Mage_Core_Controller_Front_Action
{

    public function indexAction()
    {
         $this->_redirectUrl('/');
    }

    public function resultAction()
    {
         $this->_redirectUrl('/');
    }
}

Any requests will be redirected to home.

OTHER TIPS

Since URL rewrite does not work for result page (same for disabling module output), here another more flexible solution:

Solution 1:

Create an extension to redirect users to configured "CMS No Route Page".

  1. listen to two events:

    • controller_action_predispatch_catalogsearch_advanced_index
    • controller_action_predispatch_catalogsearch_advanced_result
  2. add an observer

    public function disableAdvancedSearch(Varien_Event_Observer $observer)
    {
        if (!Mage::getStoreConfigFlag('catalog/search/enable_advanced_search')) {
            $path = Mage::getStoreConfig('web/default/cms_no_route');
            $observer->getControllerAction()->getResponse()->setRedirect(Mage::getUrl($path));
        }
    }
    
  3. add config section

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <sections>
            <catalog>
                <groups>
                    <search>
                        <fields>
                            <enable_advanced_search translate="label">
                                <label>Enable Advanced Search</label>
                                <frontend_type>select</frontend_type>
                                <source_model>adminhtml/system_config_source_enabledisable</source_model>
                                <sort_order>999</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>1</show_in_store>
                            </enable_advanced_search>
                        </fields>
                    </search>
                </groups>
            </catalog>
        </sections>
    </config>
    

M1: https://github.com/sreichel/magento-StackExchange_DisableAdvancedSearch
M2: https://github.com/sreichel/magento2-StackExchange_DisableAdvancedSearch

Solution 2:

Add this (or something better) to .htaccess ...

RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^catalogsearch/advanced/(.*)$ /no-route [R=301,L]

Yes you are right, you can use a rewrite option because Magento has catalogSearch module for search functionality if we will disable that extension then it will stop simple search as well.

There is one more option which you can use, you can override Advance catalog search template file which location is following:- base/default/template/catalogsearch/advance/form.phtml file, you can put this file with same folder structure with a different design into your theme folder. So you can remove search form from there and can use a different design.

I think instead of rewriting the controller you can use Magento's URL Redirect Management feature

i.e in Admin go to

Catalog>Url Redirects > Add URL redirect> Select URL redirect Type to "Custom"

Choose Store, Request Path: catalogsearch/advanced/ Target Path: Any page line no-route or home page Redirect Type: Permanent (301) "So that crawlers will crawl target path instead of advance search url"

IN Magento 2.1, you can disable the search module from the backend: go to STORES >> CONFIGURATION >> ADVANCED >> ADVANCED >> Disable Modules Output scroll to Magento_Search and/or Magento_CatalogSearch and disable it then save. Thereafter remember to clear the cache.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top