4

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.

3

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.

  • thanks a lot for reply, \app\code\core\Mage\Catalog\Model\Layer\Filter/category.php category.php file here = codepad.org/8MHoz2NJ i think i can't simply replace the code in this file. it's really going to be difficult for me to rewrite a method now.... from next time, i will do it. now can you please rewrite method and tell me which code i have to replace by which code.... – Baby in Magento Mar 9 '15 at 8:12
  • 1
    Here is an example on how you can rewrite a model. And you only need to change the method _getItemsData. the code you need to replace is in the answer. – Marius Mar 9 '15 at 8:15
  • okay marius, i will try that and tell you later about result.... – Baby in Magento Mar 9 '15 at 8:17

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.