3

If I add product to a category the catalog search works perfectly. But I dont want to use category filter on this. Actually I dont use category in my project.

Edit: I want to show category-less products on catalogsearch result page. That's why I want to remove category filter.

So, how can I remove category filter on catalog search? I think It's about core code but I dont know which file I need to edit.

6 Answers 6

4

Add the following node to local.xml file of your theme:

<catalogsearch_result_index>
    <reference name="catalogsearch.leftnav">
        <action method="unsetChild"><name>category_filter</name></action>
    </reference>
</catalogsearch_result_index>
9
  • I want to show category-less products on catalogsearch result page. That's why I want to remove category filter. Commented Apr 22, 2014 at 13:59
  • Isn't it what my answer addresses? Commented Apr 22, 2014 at 14:29
  • It doesnt work, For test only one product has category, the other ones not. Now, search returning one product only. Commented Apr 22, 2014 at 14:41
  • I think there is a has-category-filter or something on core code. Commented Apr 22, 2014 at 14:45
  • What is the "Visibility" setting of your product? Commented Apr 22, 2014 at 16:31
3

Assuming you're using the default magento layout-

Open app/design/frontend/default/default/layout/catalogsearch.xml

<catalogsearch_result_index translate="label">
    <reference name="root" >
        <action method="setTemplate" >< template >page/1column.phtml< /template ></action>
    </reference>
</catalogsearch_result_index>

Since you are not using Layer left block this will solve your issue.

1
  • I think I cant tell the problem correctly. The problem is I want to show category-less products on catalog search result page. Because I dont use category on magento. Commented Apr 22, 2014 at 13:54
1

If you want to do it via XML you should edit catalog.xml

replace:

<block type="catalog/layer_view" name="catalog.leftnav" 
    after="currency" template="catalog/layer/view.phtml" />  

with this:

<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml">  
    <action method="unsetChild"><alias>category_filter</alias></action>
</block>
2
  • I think I cant tell the problem correctly. The problem is I want to show category-less products on catalog search result page. Because I dont use category on magento. Commented Apr 22, 2014 at 13:51
  • This is not on the catalog search page...it is on catalog listing page
    – tread
    Commented Oct 31, 2016 at 8:20
1

You may be better off creating a category to hold the products, include in Menu set to false. You can also set the category to not available and use getChildrenCategoriesWithInactive, and assign all your "search" based non category products to search over only this category.

You'll want to look over the Layer Filter Category, possibly overriding getCategory() or apply() within: app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php

For example:

    /**
     * Get selected category object
     *
     * @return Mage_Catalog_Model_Category
     */
    public function getCategory()
    {
        $rootCat = 4; // <- your new category ID
        $this->_categoryId = $rootCat;
        $category = Mage::getModel('catalog/category')->load($rootCat);

        Mage::register('current_category_filter', $category, true);

        return $category;
    }

Related Stackoverflow question:

Also, if you do go this route, don't edit the core file but make a module version or at the very least an app/code/local/Mage/ copy.

1

You could simply add all products to the root category. As if there is no category set then this category is added as a filter to search results.

This would save you save you from having to change core code and I think it would give you the results you are looking for.

The root category can be returned via Mage::app()->getStore()->getRootCategoryId()

-1
<?php $catalogSearchHelper =  $this->helper('catalogsearch'); ?>
<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
    <div class="form-search">
        <label for="search"><?php echo $this->__('Search:') ?></label>
        <input id="search" type="text" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="input-text" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" />
        <button type="submit" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Search')) ?>" class="button"><span><span><?php echo $this->__('Search') ?></span></span></button>
        <div id="search_autocomplete" class="search-autocomplete"></div>
        <script type="text/javascript">
        //<![CDATA[
            var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Search entire store here...')) ?>');
            searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');
        //]]>
        </script>
    </div>
</form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.