hide only some categories from layered navigation in magento
-
12-12-2019 - |
Question
we are using custom theme and 1.9 version
we have lot of categories in magento site. we have to hide some categories from "layererd navigation".
for some categories we put "NO" for "Include in Navigation Menu " in admin panel.
but still those categories are displaying under "shop by" in layered navigation.
how to hide only some categories from layered navigation.
please help me to find solution....
thanks in advance.
Solution
Include in navigation menu flag does not apply by default to layered nav.
If you want to do so, you need to rewrite the method Mage_Catalog_Model_Layer_Filter_Category::_getItemsData
.
You need to replace this
$categories = $categoty->getChildrenCategories();
With something like this (untested code)
$categories = $categoty->getCollection(); //Yes..$categoty is misspelled on purpose
$categories->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('all_children')
->addAttributeToSelect('is_anchor')
->setOrder('position', Varien_Db_Select::SQL_ASC)
->joinUrlRewrite()
->addIdFilter($category->getChildren())
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1);
unfortunately you cannot use
$categories = $categoty->getChildrenCategories();
$categories->addAttributeToFilter('include_in_menu', 1);
Like you should because on the first line the category collection is loaded and any oher filter does not affect it.