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:
- The
top.menu
block'sgetHtml()
method is called. - The
page_block_html_topmenu_gethtml_before
event is fired to get items added to the block's $_menu attribute. 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._addCategoriesToMenu()
recursively adds the categories and their subcategories to the menu, usingif (!$category->getIsActive()) { continue; }
to pass on categories that are not active, but does not checkinclude_in_menu
at all.- Back in the
top.Menu
block'sgetHtml
method, the menu is rendered, either using a renderer class (if acatalog.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?