This is because Magento lazily loads the category model. The getChildrenCategories() method in the Mage_Catalog_Model_Category model returns a collection of category models, and Magento only loads the model’s master data, not the additional EAV data for each model. The include_in_menu attribute is stored in the EAV data store and is not loaded.
Each category can be force loaded by calling $_category->load(); which will force Magento to download additional EAV data for each category.
// Loop through the categories foreach ($_sub_categories as $_category) { $_category->load(); if ($_category->getIsActive() && $_category->getIncludeInMenu()) { <echo navigation link> } }
This modifies the _data array as follows:
array (size=15) 'entity_id' => string '16' (length=2) 'entity_type_id' => string '3' (length=1) 'attribute_set_id' => string '3' (length=1) 'parent_id' => string '15' (length=2) 'created_at' => string '2011-11-16 12:16:27' (length=19) 'updated_at' => string '2011-12-19 16:19:08' (length=19) 'path' => string '1/15/16' (length=7) 'position' => string '1' (length=1) 'level' => string '2' (length=1) 'children_count' => string '8' (length=1) 'is_active' => string '1' (length=1) 'request_path' => null 'name' => string 'Vacuum Cleaners' (length=15) 'url_key' => string 'vacuum-cleaners' (length=15) 'is_anchor' => string '1' (length=1)
For this:
array (size=33) 'entity_id' => string '16' (length=2) 'entity_type_id' => string '3' (length=1) 'attribute_set_id' => string '3' (length=1) 'parent_id' => string '15' (length=2) 'created_at' => string '2011-11-16 12:16:27' (length=19) 'updated_at' => string '2011-12-19 16:19:08' (length=19) 'path' => string '1/15/16' (length=7) 'position' => string '1' (length=1) 'level' => string '2' (length=1) 'children_count' => string '8' (length=1) 'is_active' => string '1' (length=1) 'request_path' => null 'name' => string 'Vacuum Cleaners' (length=15) 'url_key' => string 'vacuum-cleaners' (length=15) 'is_anchor' => string '1' (length=1) 'meta_title' => null 'display_mode' => string 'PRODUCTS' (length=8) 'custom_design' => null 'page_layout' => null 'url_path' => string 'vacuum-cleaners' (length=15) 'image' => string 'heading_vacuums_1.png' (length=21) 'include_in_menu' => string '1' (length=1) 'landing_page' => null 'custom_use_parent_settings' => string '0' (length=1) 'custom_apply_to_products' => string '0' (length=1) 'filter_price_range' => null 'description' => null 'meta_keywords' => null 'meta_description' => null 'custom_layout_update' => null 'available_sort_by' => null 'custom_design_from' => null 'custom_design_to' => null
Which includes the include_in_menu attribute.
source share