/** * Load terms and try to sort it by names * * @return $this */ protected function _loadTerms() { if (empty($this->_terms)) { $this->_terms = []; $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; }
/** * @return $this */ protected function _prepareCollection() { $this->_collection = $this->_queriesFactory->create(); $this->_collection->setRecentQueryFilter(); if ($this->getRequest()->getParam('store')) { $this->_collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store')); } elseif ($this->getRequest()->getParam('website')) { $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', ['in' => $storeIds]); } elseif ($this->getRequest()->getParam('group')) { $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', ['in' => $storeIds]); } $this->setCollection($this->_collection); return parent::_prepareCollection(); }
/** * {@inheritdoc} */ protected function _prepareCollection() { $this->_collection = $this->_queriesFactory->create(); if ($this->getRequest()->getParam('store')) { $storeIds = $this->getRequest()->getParam('store'); } elseif ($this->getRequest()->getParam('website')) { $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); } elseif ($this->getRequest()->getParam('group')) { $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); } else { $storeIds = ''; } $this->_collection->setPopularQueryFilter($storeIds); $this->setCollection($this->_collection); return parent::_prepareCollection(); }
/** * Retrieve collection of suggest queries * * @return QueryCollection */ public function getSuggestCollection() { $collection = $this->getData('suggest_collection'); if ($collection === null) { $collection = $this->_queryCollectionFactory->create()->setStoreId($this->getStoreId())->setQueryFilter($this->getQueryText()); $this->setData('suggest_collection', $collection); } return $collection; }