/** * Get data array for building category filter items * * @return array */ protected function _getItemsData() { if ('catalogsearch' == Mage::app()->getRequest()->getModuleName()) { $items = parent::_getItemsData(); // exclude foreach ($items as $key => $item) { if ($this->isExcluded($item['value'])) { unset($items[$key]); } } // Hide one value if (Mage::getStoreConfig('amshopby/general/hide_one_value') && count($items) == 1) { $items = array(); } return $items; } $isStatic2LevelTree = self::DT_STATIC2LVL == $this->_displayType; $isShowSubCats = self::DT_WSUBCAT == $this->_displayType; $isAdvanced = self::DT_ADVANCED == $this->_displayType; $isCountEnabled = Mage::getStoreConfig('catalog/layered_navigation/display_product_count'); if (is_null($isCountEnabled)) { // Magento 1.4 has no option $isCountEnabled = true; } if ($isAdvanced) { return array(0 => 1); } // always use root category $currentCategory = $this->getCategory(); $root = Mage::getModel('catalog/category')->load($this->getLayer()->getCurrentStore()->getRootCategoryId()); $categories = $isStatic2LevelTree ? $root->getChildrenCategories() : $currentCategory->getChildrenCategories(); if ($isStatic2LevelTree) { $this->getLayer()->setCurrentCategory($root); } if ($isCountEnabled) { $this->getLayer()->getProductCollection()->addCountToCategories($categories); } $data = array(); $startLevel = 0; if ($isShowSubCats) { $isNotRoot = $root->getId() != $currentCategory->getId(); //Get parent category of the current category if ($isNotRoot) { $parent = $currentCategory->getParentCategory(); if ($parent->getId() != $root->getId() && !$this->isExcluded($parent->getId())) { $data[] = $this->_prepareItemData($parent, false, 0, false, false); } } //Add current category if ($isNotRoot) { $startLevel = count($data) > 0 ? 2 : 1; $data[] = $this->_prepareItemData($currentCategory, true, $startLevel, false, false); } } foreach ($categories as $category) { $id = $category->getId(); if ($this->isExcluded($id)) { continue; } $data[] = $this->_prepareItemData($category, $id == $currentCategory->getId(), $startLevel + 1, false, $isCountEnabled); if ($isShowSubCats || $isStatic2LevelTree) { $children = $category->getChildrenCategories(); if ($children && count($children)) { //remember that category has children $last = count($data) - 1; if ($data[$last]) { $data[$last]['has_children'] = true; } $this->getLayer()->getProductCollection()->addCountToCategories($children); foreach ($children as $child) { // we shoul have all categories in the top navigation cache, so no additional queries if ($this->isExcluded($child->getId())) { continue; } $isFolded = $currentCategory->getParentId() != $child->getParentId(); $isSelected = $currentCategory->getId() == $child->getId(); if ($isSelected && $data[$last]) { $data[$last]['is_child_selected'] = true; } $row = $this->_prepareItemData($child, $isSelected, $startLevel + 2, $isFolded, $isCountEnabled); $data[] = $row; } } } //if add sub-categories } //restore category if ($isStatic2LevelTree) { $this->getLayer()->setCurrentCategory($currentCategory); } return $data; }