Пример #1
0
 /**
  * Load terms and try to sort it by names
  *
  * @return $this
  */
 protected function _loadTerms()
 {
     if (empty($this->_terms)) {
         $this->_terms = array();
         $terms = $this->_queryCollectionFactory->create()->setPopularQueryFilter($this->_storeManager->getStore()->getId())->setPageSize(100)->load()->getItems();
         if (count($terms) == 0) {
             return $this;
         }
         $this->_maxPopularity = reset($terms)->getPopularity();
         $this->_minPopularity = end($terms)->getPopularity();
         $range = $this->_maxPopularity - $this->_minPopularity;
         $range = $range == 0 ? 1 : $range;
         foreach ($terms as $term) {
             if (!$term->getPopularity()) {
                 continue;
             }
             $term->setRatio(($term->getPopularity() - $this->_minPopularity) / $range);
             $temp[$term->getName()] = $term;
             $termKeys[] = $term->getName();
         }
         natcasesort($termKeys);
         foreach ($termKeys as $termKey) {
             $this->_terms[$termKey] = $temp[$termKey];
         }
     }
     return $this;
 }
Пример #2
0
 /**
  * @return $this
  */
 protected function _prepareCollection()
 {
     if (!$this->_moduleManager->isEnabled('Magento_CatalogSearch')) {
         return parent::_prepareCollection();
     }
     $this->_collection = $this->_queriesFactory->create();
     $this->_collection->setRecentQueryFilter();
     if ($this->getRequest()->getParam('store')) {
         $this->_collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store'));
     } else {
         if ($this->getRequest()->getParam('website')) {
             $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
             $this->_collection->addFieldToFilter('store_id', array('in' => $storeIds));
         } else {
             if ($this->getRequest()->getParam('group')) {
                 $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
                 $this->_collection->addFieldToFilter('store_id', array('in' => $storeIds));
             }
         }
     }
     $this->setCollection($this->_collection);
     return parent::_prepareCollection();
 }
Пример #3
0
 /**
  * Retrieve collection of suggest queries
  *
  * @return QueryCollection
  */
 public function getSuggestCollection()
 {
     $collection = $this->getData('suggest_collection');
     if (is_null($collection)) {
         $collection = $this->_queryCollectionFactory->create()->setStoreId($this->getStoreId())->setQueryFilter($this->getQueryText());
         $this->setData('suggest_collection', $collection);
     }
     return $collection;
 }