protected function _getItemsData() { if (!Mage::helper('sm_shopby')->isEnabled()) { return parent::_getItemsData(); } $key = $this->getLayer()->getStateKey() . '_SUBCATEGORIES'; $data = $this->getLayer()->getAggregator()->getCacheData($key); if ($data === null) { $categoty = $this->getCategory(); $categories = $categoty->getChildrenCategories(); $this->getLayer()->getProductCollection()->addCountToCategories($categories); $data = array(); foreach ($categories as $category) { if ($category->getIsActive() && $category->getProductCount()) { $urlKey = $category->getUrlKey(); if (empty($urlKey)) { $urlKey = $category->getId(); } $data[] = array('label' => Mage::helper('core')->htmlEscape($category->getName()), 'value' => $urlKey, 'count' => $category->getProductCount()); } } $tags = $this->getLayer()->getStateTags(); $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags); } return $data; }
/** * Get data array for building category filter items * * @return array */ protected function _getItemsData() { if (!Mage::helper('catalin_seo')->isEnabled()) { return parent::_getItemsData(); } $key = $this->getLayer()->getStateKey() . '_SUBCATEGORIES'; $data = $this->getLayer()->getAggregator()->getCacheData($key); if ($data === null) { $currentCategory = $this->getCategory(); /** @var $currentCategory Mage_Catalog_Model_Category */ $categories = $this->getChildrenCategories($currentCategory); $this->getLayer()->getProductCollection()->addCountToCategories($categories); $data = array(); foreach ($categories as $category) { if ($category->getIsActive() && $category->getProductCount()) { if (Mage::helper('catalin_seo')->isCategoryLinksEnabled()) { $urlKey = $category->getUrl(); } else { $urlKey = $category->getUrlKey(); if (empty($urlKey)) { $urlKey = $category->getId(); } else { $urlKey = $category->getId() . '-' . $urlKey; } } $data[] = array('label' => Mage::helper('core')->escapeHtml($category->getName()), 'value' => $urlKey, 'count' => $category->getProductCount()); } } $tags = $this->getLayer()->getStateTags(); $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags); } return $data; }
/** * Get data array for building category filter items * * @return array */ protected function _getItemsData() { if (!Mage::helper('searchanise/ApiSe')->checkSearchaniseResult(true)) { return parent::_getItemsData(); } $collection = $this->getLayer()->getProductCollection(); if (!method_exists($collection, 'checkSearchaniseResult') || !$collection->checkSearchaniseResult()) { return parent::_getItemsData(); } $key = $this->getLayer()->getStateKey() . '_SUBCATEGORIES'; $data = $this->getLayer()->getAggregator()->getCacheData($key); if ($data === null) { $categoty = $this->getCategory(); /** @var $categoty Mage_Catalog_Model_Categeory */ $categories = $categoty->getChildrenCategories(); $this->getLayer()->getProductCollection()->addCountToCategories($categories); $data = array(); foreach ($categories as $category) { $productCount = $collection->getSearchaniseRequest()->getCountProductCategory($category); if ($category->getIsActive() && $productCount) { $data[] = array('label' => Mage::helper('core')->htmlEscape($category->getName()), 'value' => $category->getId(), 'count' => $productCount); } } $tags = $this->getLayer()->getStateTags(); $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags); } return $data; }
/** * Get data array for building category filter items * * @return array */ protected function _getItemsData() { if ('catalogsearch' == Mage::app()->getRequest()->getModuleName()) { return parent::_getItemsData(); } $isStatic2LevelTree = 3 == Mage::getStoreConfig('amshopby/general/categories_type'); $isShowSubCats = 2 == Mage::getStoreConfig('amshopby/general/categories_type'); // alwaus 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); } $this->getLayer()->getProductCollection()->addCountToCategories($categories); $data = array(); $exclude = Mage::getStoreConfig('amshopby/general/exclude_cat'); if ($exclude) { $exclude = explode(',', preg_replace('/[^\\d,]+/', '', $exclude)); } else { $exclude = array(); } foreach ($categories as $category) { $id = $category->getId(); if (in_array($id, $exclude)) { continue; } $data[] = $this->_prepareItemData($category, $id, $id == $currentCategory->getId()); 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 (in_array($child->getId(), $exclude)) { continue; } $isFolded = $currentCategory->getParentId() != $child->getParentId(); $isSelected = $currentCategory->getId() == $child->getId(); if ($isSelected && $data[$last]) { $data[$last]['is_child_selected'] = true; } $data[] = $this->_prepareItemData($child, $id, $isSelected, 2, $isFolded); } } } //if add sub-categories } //restore category if ($isStatic2LevelTree) { $this->getLayer()->setCurrentCategory($currentCategory); } return $data; }
protected function _getItemsData() { $collection = $this->getLayer()->getProductCollection(); $isSolrCollection = $collection instanceof DMC_Solr_Model_SolrServer_Adapter_Product_Collection; if ($isSolrCollection) { $helper = Mage::helper('solr'); if (!$helper->showCategories()) { return array(); } $fselect = clone $collection->getSelect($helper->catalogCategoryMultiselectEnabled()); $solrField = "available_category_ids"; $fselect->param('facet', 'true', true); $fselect->param('facet.field', $solrField, true); $responce = Mage::helper('solr')->getSolr()->fetchAll($fselect); $optionsCount = $responce->__get('facet_counts')->facet_fields->{$solrField}; $tempArr = array(); foreach ($optionsCount as $catId => $count) { if ($count) { $tempArr[$catId] = $count; } } $tempArr2 = array(); unset($optionsCount); $categoryCollection = Mage::getModel('catalog/category')->getResourceCollection()->addIsActiveFilter()->addAttributeToSelect('name')->addFieldToFilter('level', array('gteq' => 3))->addIdFilter(array_keys($tempArr)); foreach ($tempArr as $catId => $count) { foreach ($categoryCollection as $categoryObj) { if ($categoryObj->getId() == $catId) { $tempArr2[$catId] = array(); $tempArr2[$catId]['label'] = $categoryObj->getName(); $tempArr2[$catId]['count'] = $count; break; } } } unset($tempArr); $data = array(); foreach ($tempArr2 as $catId => $itemData) { $data[] = array('label' => $itemData['label'], 'value' => $catId, 'count' => $itemData['count']); } return $data; } else { return parent::_getItemsData(); } }
/** * Get data array for building category filter items * * @return array */ protected function _getItemsData() { if (!Mage::helper('klevu_search/config')->isExtensionConfigured() || !Mage::helper('klevu_search')->isCatalogSearch()) { return parent::_getItemsData(); } $key = $this->getLayer()->getStateKey() . '_SUBCATEGORIES'; $data = $this->getLayer()->getAggregator()->getCacheData($key); if ($data === null) { // Fetch filters from Klevu $filters = $this->_getKlevuCategoryFilters(); if ($this->getLayer()->getProductCollection()->count() == 0) { return array(); // No visible results found in search } // Prepare all the available category names $category_names = array(); foreach ($filters as $filter) { $category_names[] = $filter['label']; } $category = $this->getCategory(); // Get the all categories returned from klevu, and apply the current parent category. $categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('is_active')->addFieldToFilter('name', array('in' => $category_names)); $this->getLayer()->getProductCollection()->addCountToCategories($categories); $data = array(); $k_cat = Mage::app()->getRequest()->getParam('cat'); if (!isset($k_cat)) { foreach ($categories as $category) { // Ensure the category exists within the Klevu filters. if (!($klevu_category = $this->_findKlevuCategory($category, $filters))) { continue; } if ($category->getIsActive() && $category->getProductCount()) { $data[] = array('label' => Mage::helper('core')->escapeHtml($category->getName()), 'value' => $category->getId(), 'count' => $klevu_category['count']); } } } $tags = $this->getLayer()->getStateTags(); $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags); } return $data; }
protected function _getItemsData() { if ($this->_layeredHelper->getCategoryDisplay() != 2) { //tree listing, extra listing currently ignored return parent::_getItemsData(); } $key = $this->getLayer()->getStateKey() . '_SUBCATEGORIES'; $data = $this->getLayer()->getAggregator()->getCacheData($key); if ($data === null) { $this->_currentCategory = $this->getCategory(); $root = Mage::getModel('catalog/category')->load($this->getLayer()->getCurrentStore()->getRootCategoryId()); $this->getLayer()->setCurrentCategory($root); $categories = $root->getChildrenCategories(); $level = 1; $this->collectCategories($categories, $level); $data = $this->categData; $this->getLayer()->setCurrentCategory($this->_currentCategory); $tags = $this->getLayer()->getStateTags(); $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags); } return $data; }
/** * Retrieves current items data. * * @return array */ protected function _getItemsData() { if (!Mage::helper('elasticsearch')->isActiveEngine()) { return parent::_getItemsData(); } $key = $this->getLayer()->getStateKey() . '_SUBCATEGORIES'; $data = $this->getLayer()->getCacheData($key); if ($data === null) { /** @var $category Mage_Catalog_Model_Categeory */ $category = $this->getCategory(); $categories = $category->getChildrenCategories(); $productCollection = $this->getLayer()->getProductCollection(); $facets = $productCollection->getFacetedData('categories'); $facetsTerms = array_key_exists('terms', $facets) ? $facets['terms'] : array(); $data = array(); foreach ($categories as $category) { $categoryId = $category->getId(); foreach ($facetsTerms as $facetTerm) { $term = $facetTerm['term']; $count = $facetTerm['count']; if ($term == $categoryId) { $category->setProductCount($count); } else { $category->setProductCount(0); } if ($category->getIsActive() && $category->getProductCount()) { $data[] = array('label' => Mage::helper('core')->escapeHtml($category->getName()), 'value' => $categoryId, 'count' => $category->getProductCount()); } } } $tags = $this->getLayer()->getStateTags(); $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags); } return $data; }
/** * Get data array for building category filter items * * @return array */ protected function _getItemsData() { if ('catalogsearch' == Mage::app()->getRequest()->getModuleName()) { return parent::_getItemsData(); } $_displayType = Mage::getStoreConfig('amshopby/general/categories_type'); $isStatic2LevelTree = self::DT_STATIC2LVL == $_displayType; $isShowSubCats = self::DT_WSUBCAT == $_displayType; $isAdvanced = self::DT_ADVANCED == $_displayType; if ($isAdvanced) { return array(0 => 1); } // alwaus 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); } $this->getLayer()->getProductCollection()->addCountToCategories($categories); $data = array(); $exclude = Mage::getStoreConfig('amshopby/general/exclude_cat'); if ($exclude) { $exclude = explode(',', preg_replace('/[^\\d,]+/', '', $exclude)); } else { $exclude = 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() && !in_array($parent->getId(), $exclude)) { $data[] = $this->_prepareItemData($parent, $parent->getId(), false, 0, false, true); } } //Add current category if ($isNotRoot) { $startLevel = count($data) > 0 ? 2 : 1; $data[] = $this->_prepareItemData($currentCategory, $currentCategory->getId(), true, $startLevel, false, true); } } foreach ($categories as $category) { $id = $category->getId(); if (in_array($id, $exclude)) { continue; } $data[] = $this->_prepareItemData($category, $id, $id == $currentCategory->getId(), $startLevel + 1, false); 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 (in_array($child->getId(), $exclude)) { 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, $id, $isSelected, $startLevel + 2, $isFolded); $data[] = $row; } } } //if add sub-categories } //restore category if ($isStatic2LevelTree) { $this->getLayer()->setCurrentCategory($currentCategory); } return $data; }