コード例 #1
0
 /**
  * This method in Mage_Catalog_Model_Layer_Filter_Category would ensure when a category filter is remove, the parent
  * category is applied as a filter. This isn't expected functionality for Klevu, and has been reset to a null value.
  * @return null
  */
 public function getResetValue()
 {
     if (!Mage::helper('klevu_search/config')->isExtensionConfigured() || !Mage::helper('klevu_search')->isCatalogSearch()) {
         return parent::getResetValue();
     }
     return null;
 }
コード例 #2
0
ファイル: Category.php プロジェクト: sagmahajan/aswan_release
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     // very small optimization
     $catId = (int) Mage::helper('adjnav')->getParam($this->getRequestVar());
     if ($catId) {
         $request->setParam($this->getRequestVar(), $catId);
         parent::apply($request, $filterBlock);
     }
     $category = $this->getCategory();
     if (!Mage::registry('current_category_filter')) {
         Mage::register('current_category_filter', $category);
     }
     if (!isset($filter) || !$filter) {
         $this->addCategoryFilter($category, null);
         return $this;
     }
     $this->_appliedCategory = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($filter);
     if ($this->_isValidCategory($this->_appliedCategory)) {
         /*
         $this->getLayer()->getProductCollection()
             ->addCategoryFilter($this->_appliedCategory);
         */
         $this->addCategoryFilter($this->_appliedCategory, $filter);
         $this->getLayer()->getState()->addFilter($this->_createItem($this->_appliedCategory->getName(), $filter));
     }
     return $this;
 }
コード例 #3
0
ファイル: Category.php プロジェクト: protechhelp/gamamba
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     if (Mage::getStoreConfig('mageworx_seo/seosuite/disable_layered_rewrites')) {
         return parent::apply($request, $filterBlock);
     }
     $filter = $request->getParam($this->getRequestVar());
     if (is_null($filter)) {
         return parent::apply($request, $filterBlock);
     }
     if (!is_numeric($filter)) {
         if (Mage::registry('current_category')) {
             $collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('parent_id', Mage::registry('current_category')->getId())->addAttributeToFilter('is_active', 1)->addAttributeToSelect('name')->addAttributeToFilter('name', $filter);
             if (count($collection) == 0) {
                 return parent::apply($request, $filterBlock);
             }
             $this->_appliedCategory = $collection->getFirstItem();
             if (!$this->_appliedCategory->getProductCollection()->count()) {
                 $this->_appliedCategory = $this->_getCategoryByName($filter);
             }
         } else {
             $this->_appliedCategory = $this->_getCategoryByName($filter);
         }
         if ($this->_appliedCategory) {
             $this->_categoryId = $filter = $this->_appliedCategory->getId();
         }
     } else {
         $this->_categoryId = $filter;
         $this->_appliedCategory = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($filter);
     }
     if ($this->_isValidCategory($this->_appliedCategory)) {
         $this->getLayer()->getProductCollection()->addCategoryFilter($this->_appliedCategory);
         $this->getLayer()->getState()->addFilter($this->_createItem($this->_appliedCategory->getName(), $filter));
     }
     return $this;
 }
コード例 #4
0
ファイル: Category.php プロジェクト: kozinthetdbp/shopmyar
 /**
  * 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;
 }
コード例 #5
0
ファイル: Category.php プロジェクト: novayadi85/navicet
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     $catId = (int) Mage::helper('multilayer')->getParam($this->getRequestVar());
     if ($catId) {
         $request->setParam($this->getRequestVar(), $catId);
         parent::apply($request, $filterBlock);
     }
     return $this;
 }
コード例 #6
0
ファイル: Categorysearch.php プロジェクト: monarcmoso/beta2
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     // very small optimization
     $catId = (int) $request->getParam($this->getRequestVar());
     if ($catId) {
         parent::apply($request, $filterBlock);
     }
     return $this;
 }
コード例 #7
0
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     // very small optimization
     $catId = (int) Mage::helper('layerednav')->getParam($this->getRequestVar());
     if ($catId) {
         $request->setParam($this->getRequestVar(), $catId);
         parent::apply($request, $filterBlock);
     }
     return $this;
 }
コード例 #8
0
 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();
     }
 }
 protected function _initItems()
 {
     if ('catalogsearch' == Mage::app()->getRequest()->getModuleName()) {
         return parent::_initItems();
     }
     $data = $this->_getItemsData();
     $items = array();
     foreach ($data as $itemData) {
         if (!$itemData) {
             continue;
         }
         $obj = new Varien_Object();
         $obj->setData($itemData);
         $obj->setUrl($itemData['value']);
         $items[] = $obj;
     }
     $this->_items = $items;
     return $this;
 }
コード例 #10
0
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     if (!Mage::helper('sm_shopby')->isEnabled()) {
         return parent::apply($request, $filterBlock);
     }
     $filter = $request->getParam($this->getRequestVar());
     if (!$filter) {
         return $this;
     }
     $this->_appliedCategory = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->loadByAttribute('url_key', $filter);
     if (!$this->_appliedCategory instanceof Mage_Catalog_Model_Category) {
         return parent::apply($request, $filterBlock);
     }
     $this->_categoryId = $this->_appliedCategory->getId();
     Mage::register('current_category_filter', $this->getCategory(), true);
     if ($this->_isValidCategory($this->_appliedCategory)) {
         $this->getLayer()->getProductCollection()->addCategoryFilter($this->_appliedCategory);
         $this->getLayer()->getState()->addFilter($this->_createItem($this->_appliedCategory->getName(), $filter));
     }
     return $this;
 }
コード例 #11
0
ファイル: CategoryTest.php プロジェクト: natxetee/magento2
 /**
  * @depends testApply
  */
 public function testGetItems(Mage_Catalog_Model_Layer_Filter_Category $modelApplied)
 {
     $items = $modelApplied->getItems();
     $this->assertInternalType('array', $items);
     $this->assertEquals(1, count($items));
     /** @var $item Mage_Catalog_Model_Layer_Filter_Item */
     $item = $items[0];
     $this->assertInstanceOf('Mage_Catalog_Model_Layer_Filter_Item', $item);
     $this->assertSame($modelApplied, $item->getFilter());
     $this->assertEquals('Category 1.1', $item->getLabel());
     $this->assertEquals(4, $item->getValue());
     $this->assertEquals(1, $item->getCount());
 }
コード例 #12
0
 /**
  * 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;
 }
コード例 #13
0
 /**
  * Create filter item object
  *
  * @param string $label Label of the filter value
  * @param mixed  $value Value of the filter
  * @param int    $count Number of result (default is 0)
  * @param string $url   URL of the category
  *
  * @return Mage_Catalog_Model_Layer_Filter_Item
  */
 protected function _createItem($label, $value, $count = 0, $url = null)
 {
     $item = parent::_createItem($label, $value, $count);
     if ($this->getUseUrlRewrites()) {
         $item = Mage::getModel('smile_elasticsearch/catalog_layer_filter_item_category')->setFilter($this)->setLabel($label)->setValue($value)->setCount($count)->setCategoryUrl($url);
     }
     return $item;
 }
コード例 #14
0
 /**
  * do not show the level 2 items if the tree category listing is selected
  */
 public function getResetValue()
 {
     if ($this->_layeredHelper->getCategoryDisplay() != 2) {
         //tree listing
         parent::getResetValue();
     } else {
         if ($this->_appliedCategory) {
             /**
              * Revert path ids
              */
             $pathIds = array_reverse($this->_appliedCategory->getPathIds());
             $curCategoryId = $this->getLayer()->getCurrentCategory()->getId();
             if (Mage::getModel('catalog/category')->load($curCategoryId)->getLevel() == 2) {
                 return null;
             }
             if (isset($pathIds[1]) && $pathIds[1] != $curCategoryId) {
                 return $pathIds[1];
             }
         }
         return null;
     }
 }