1

Two attributes on the Category model seem possibly relevant to determining whether a category should be shown in the Topmenu: Is Active (is_active) and Include in Navigation Menu (include_in_menu).

Despite the seemingly obvious intended purpose for Include in Navigation Menu, a review of the code shows that Magento doesn't even check it when adding categories to the Topmenu--it only checks the is_active attribute.

Am I missing the point of the Include in Navigation Menu attribute, or is this potentially a bug?

For completeness, here's an overview of how I understand Magento's process of rendering the Topmenu:

  1. The top.menu block's getHtml() method is called.
  2. The page_block_html_topmenu_gethtml_before event is fired to get items added to the block's $_menu attribute.
  3. Mage_Catalog_Model_Observer::addCatalogToTopmenuItems observes the event, retrieves the store's top-level categories, and calls its sibling method _addCategoriesToMenu() to add them to the menu.
  4. _addCategoriesToMenu() recursively adds the categories and their subcategories to the menu, using if (!$category->getIsActive()) { continue; } to pass on categories that are not active, but does not check include_in_menu at all.
  5. Back in the top.Menu block's getHtml method, the menu is rendered, either using a renderer class (if a catalog.topnav.renderer block is configured), or otherwise the default rendering method.

Aside from the question of whether categories must also be Active in order to appear, shouldn't _addCategoriesToMenu use if (!$category->getIncludeInMenu()) { continue; } instead?

1

Mage_Catalog_Model_Resource_Category_Tree::addCollectionData already sends only active and included in menu categories.

So in Mage_Catalog_Model_Observer::_addCategoriesToMenu the $categories array is only formed by items that are active and included in the menu.

You can try in Mage_Catalog_Model_Resource_Category_Tree to remove the line 159 $collection->addAttributeToFilter('include_in_menu', 1); to disregard the filter if this is what you want.

At least, this is how I understand it.

  • 1
    Indeed you are correct, addCollectionData does add both is_active and include_in_menu filters to the entire set of categories returned. That throws a bit of a spanner in my plans, which I may move to a different question if I can't work it out. However, this question is really asking what's the purpose of having two separate attributes if the is_active attribute is used to do the what the include_in_menu attribute seems better suited. Or, in code terms, why does addCollectionData's $onlyActive parameter result in filters on both is_active and include_in_menu? – pcronin Aug 16 '15 at 15:16

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.