8

I'm struggling to remove the Category filter from the layered, because I already have a category dropdown menu in my new website, so it will be only a waste of space (and confuse my customers)

I know that this issue was already asked many times and already solved, but I tried every solution without success. I believe that this is related to the custom template I use for the website.

After looking at my local.xml file (found in my template folder) I believe that I should work around these lines:

<reference name="product_list">
        <block type="core/text_list" name="category-right" as="category-right" translate="label">
            <label>Right Column</label>
            <block type="catalog/navigation" name="catalog.category" before="-" template="catalog/navigation/category_nav.phtml"/>
            <block type="catalog/layer_view" name="catalog.leftnav" after="catalog.category" template="catalog/layer/view.phtml"/>
            <block type="filterproducts/bestsellers_home_list" name="bestseller" template="catalog/navigation/best_sellers.phtml"/>
            <block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml">
                <block type="cms/block" name="cms_images_block">
                    <action method="setBlockId"><block_id>category_right_block</block_id></action>
                </block>
            </block>
        </block>
    </reference>

The first -block type- should be the category menu (and I'm fine with that). The second -block type- builds the "filter by" menu, just below the category menu, and I'm pretty sure that the problem is here.

I believe that I should unset something inside the "catalog.leftnav" but even if I try to add this code :

<catalog_category_layered>
     <reference name="product_list">
        <action method="unsetChild"><child>category_filter</child></action>
    </reference>
</catalog_category_layered>

nothing happens. What am I doing wrong?

  • you just need to avoid category section from layered navigation and dont want to avoid other filters? – Rajeev K Tomy Oct 2 '14 at 6:36
  • exactly! but I'm going crazy to find out how.... – giancarlo Oct 2 '14 at 12:14
  • Shouldn't local.xml be in the layout folder, not the template folder? – Yumecosmos May 20 '15 at 15:38
14

Based on stackexchange.com answer:
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>
  • yes a classic clean method,+1 for that – Rajeev K Tomy Oct 2 '14 at 10:11
  • 1
    I tried, but it simply doesn't work. I belive that this is related to my custom template. In my template "catalog.xml" there isn't these lines. Anyway, I've read in stackexchange that the correct method is to work with the "local.xml" file. Other than the -.xml- method, can you suggest me other way to achieve the desidered result? – giancarlo Oct 2 '14 at 12:12
  • What's the difference between <alias> and <child>? For me both works... – versedi Feb 25 '15 at 22:01
  • There is no difference in this particular case. You can use even <action method="unsetChild"><xyz>category_filter</xyz></action> – Amasty Mar 16 '15 at 14:07
  • If like me you tried adding this into your local.xml you may then get this kind of error.... "You cannot define a correlation name 'mycustomattribute' more than once" because catalog/layer_view module is called twice-Explained here: stackoverflow.com/questions/10524017/… Use the code posted by giancarlo below <reference name="catalog.leftnav"> <action method="unsetChild"><alias>category_filter</alias></action> </reference> but add into local.xml. this worked for me on 1.8 – Tofuwarrior Sep 15 '16 at 10:28
5

Try this code first. Here we are trying to remove this via layout xml update

File : app/design/frontend/<package>/<theme>/layout/local.xml

<layout>
    <catalog_category_layered>
        <reference name="catalog.leftnav">
            <action method="unsetChild"><alias>category_filter</alias></action>
        </reference>
    </catalog_category_layered>
</layout>

This will solve your problem.

If it didn't worked, then you need to do a block rewrite. For this you need to create a module. The block that you need to rewrite is Mage_Catalog_Block_Layer_View.

Module's activation file looks like this

File : app/etc/modules/Avoid_CategoryFromLN.xml

<config>
    <modules>
         <Avoid_CategoryFromLN>
             <active>true</active>
             <codePool>local</codePool>
         </Avoid_CategoryFromLN>
     </modules>
</config>

This is how rewrite configuration looks like

File : app\code\local\Avoid/CategoryFromLN/etc/config.xml

<config>
    <modules>
        <Avoid_CategoryFromLN>
            <version>1.0.0</version>
        </Avoid_CategoryFromLN>
    </modules>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <layer_view>Avoid_CategoryFromLN_Block_Layer_View</layer_view>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

Now your rewrite block should posses this content

File : app\code\local\Avoid/CategoryFromLN/Block/Layer/View.php

<?php
class Avoid_CategoryFromLN_Block_Layer_View exteds Mage_Catalog_Block_Layer_View
{
    public function getFilters()
    {

        $filterableAttributes = $this->_getFilterableAttributes();
        foreach ($filterableAttributes as $attribute) {
            $filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
        }

        return $filters;
    }
}

Here getFilters() is the method that actually includes category filters inside layered navigation filter. We just remove that code by rewriting the core class. That's it.

Big Note: : You should keep capital letters as it is. Dont make them small letters. If you do, it will not work. Magento is strict in these things :) So revise all folder names, file names multiple times. Make sure you keep all names contents as it is

Now try again.

  • sorry, but editing the local.xml file does not gives any results. regarding the creation of a module I have some doubts about it. I'm a magento "newbie" so please bear with me. This is what I've done to create a new module as suggested: Create this new folder: "app\code\local\my_module_name\etc" Create the config.xml file Add the content you told me in the "config.xml" file Create a new folder: "app\code\local\my_module_name\block\layer" Create a new file called "view.php" Copy the content you suggested in the "view.php" file. After this I try again, but nothing changes. Do I miss something? – giancarlo Oct 2 '14 at 16:09
  • Also, I've discovered this answer in stackexchange that offer another solution : magento.stackexchange.com/questions/31631/… But I belive that this should be modified to fit my template settings. – giancarlo Oct 2 '14 at 16:20
  • nope your condfigurations are wrong. I will update my answer for you – Rajeev K Tomy Oct 2 '14 at 16:25
  • edited answer. Now it is a complete module. Feel free to use it. Please note you need to keep capital letters as it is – Rajeev K Tomy Oct 2 '14 at 16:36
  • regarding the link that you pointed out, it is not ideal in your case. If you put isAnchor to no, then the entire layered navigation get disappeared. – Rajeev K Tomy Oct 2 '14 at 16:39
5

I will post down what it worked for me as a reference for others

adding this :

<reference name="catalog.leftnav">  
<action method="unsetChild"><alias>category_filter</alias></action>
</reference>

in the custom design tab of every categories does the trick.

Remember especially to add it in the parent category, thats what did it for me.

1

The unset-child solution in local.xml works well. Please note, that if you are working with enterprise edition the reference is called "enterprisecatalog":

<reference name="enterprisecatalog.leftnav">
    <action method="unsetChild">
        <alias>category_filter</alias>
    </action>
</reference>

Side-note: You may not find any corresponding child-block definitions in any of the core XML. This is due to the fact, that children like "category_filter" are created (hard-coded) in _prepareLayout function of the corresponding catalog layer view. By using unsetChild you can, however, remove the hard-coded added child.

0

This is works https://magento.stackexchange.com/a/45249/9951

BUT

Also need add changes to app/design/frontend/rwd/default/template/catalog/layer/view.phtml

like this

if($_filter != '' && $_filter->getItemsCount())

and also need changes to /app/code/core/Mage/Catalog/Block/Layer/View.php

copy /app/code/core/Mage/Catalog/Block/Layer/View.php

to /app/code/local/Mage/Catalog/Block/Layer/View.php

and change method canShowOptions()

need change

if (&& $filter->getItemsCount())

to

if ($filter != '' && $filter->getItemsCount())

and try

0

This is what worked for me (on Magento 1.9).

Add these lines on your local.xml file:

<layout version="0.1.0">

  <default>

    <reference name="left">

      <!-- Remove layered navigation block form catalog page -->
      <remove name="catalog.leftnav"/>

      <!-- ... -->

    </reference>

    <!-- ... -->

  </default>

  <!-- ... -->

  <catalogsearch_result_index>

    <!-- Remove layered navigation from search result page -->
    <reference name="left">
      <action method="unsetChild">
        <child>catalogsearch.leftnav</child>
      </action>
    </reference>

  </catalogsearch_result_index>

  <!-- ... -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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