I have a function that retrieves menu data from Magento and outputs it to a javascript front-end.
public function getMenuData() { if (!is_null($this->_menuData)) return $this->_menuData; $blockClassName = Mage::getConfig()->getBlockClassName('custommenu/navigation'); $block = new $blockClassName(); $categories = $block->getStoreCategories(); if (is_object($categories)) $categories = $block->getStoreCategories()->getNodes(); if (Mage::getStoreConfig('custom_menu/general/ajax_load_content')) { $_moblieMenuAjaxUrl = str_replace('http:', '', Mage::getUrl('custommenu/ajaxmobilemenucontent')); $_menuAjaxUrl = str_replace('http:', '', Mage::getUrl('custommenu/ajaxmenucontent')); } else { $_moblieMenuAjaxUrl = ''; $_menuAjaxUrl = ''; } $this->_menuData = array( '_block' => $block, '_categories' => $categories, '_moblieMenuAjaxUrl' => $_moblieMenuAjaxUrl, '_menuAjaxUrl' => $_menuAjaxUrl, '_showHomeLink' => Mage::getStoreConfig('custom_menu/general/show_home_link'), '_popupWidth' => Mage::getStoreConfig('custom_menu/popup/width') + 0, '_popupTopOffset' => Mage::getStoreConfig('custom_menu/popup/top_offset') + 0, '_popupDelayBeforeDisplaying' => Mage::getStoreConfig('custom_menu/popup/delay_displaying') + 0, '_popupDelayBeforeHiding' => Mage::getStoreConfig('custom_menu/popup/delay_hiding') + 0, '_rtl' => Mage::getStoreConfig('custom_menu/general/rtl') + 0, '_mobileMenuEnabled' => Mage::getStoreConfig('custom_menu/general/mobile_menu') + 0, '_mobileMenuWidthInit' => Mage::getStoreConfig('custom_menu/general/mobile_menu_width_init') + 0, ); return $this->_menuData; }
I've been trying to find a way to modify it so that I can alter the depth of the menu being initially displayed.
I've tried changing the $categories variable over to a call to
Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('level', array('eq'=>3))->addAttributeToFilter('parent_id',array('eq' => $parent_cat_id))->load();
to try and force it to show categories at level 3 whose parent is set by the category ID, but for the life of me I just cant crack this at the moment.