/** * Load search results * * @return $this */ public function load() { $result = array(); if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) { $this->setResults($result); return $this; } $collection = $this->_catalogSearchData->getQuery()->getSearchCollection()->addAttributeToSelect('name')->addAttributeToSelect('description')->addBackendSearchFilter($this->getQuery())->setCurPage($this->getStart())->setPageSize($this->getLimit())->load(); foreach ($collection as $product) { $description = strip_tags($product->getDescription()); $result[] = array('id' => 'product/1/' . $product->getId(), 'type' => __('Product'), 'name' => $product->getName(), 'description' => $this->string->substr($description, 0, 30), 'url' => $this->_adminhtmlData->getUrl('catalog/product/edit', array('id' => $product->getId()))); } $this->setResults($result); return $this; }
/** * Prepare results for query * * @param Query $query * @return $this */ public function prepareResult($query = null) { if (!$query instanceof Query) { $query = $this->_catalogSearchData->getQuery(); } $queryText = $this->_catalogSearchData->getQueryText(); if ($query->getSynonymFor()) { $queryText = $query->getSynonymFor(); } $this->getResource()->prepareResult($this, $queryText, $query); return $this; }
/** * @param \Magento\Catalog\Model\Resource\Product\Collection $collection * @param \Magento\Catalog\Model\Category $category * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function filter($collection, \Magento\Catalog\Model\Category $category) { $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes())->addSearchFilter($this->helper->getQuery()->getQueryText())->setStore($this->storeManager->getStore())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addStoreFilter()->addUrlRewrite()->setVisibility($this->productVisibility->getVisibleInSearchIds()); }
/** * Retrieve query model object * * @return \Magento\CatalogSearch\Model\Query */ protected function _getQuery() { return $this->_catalogSearchData->getQuery(); }
/** * @param \Magento\Catalog\Model\Category $category * @return string|void */ public function toString($category) { return 'Q_' . $this->helper->getQuery()->getId() . '_' . parent::toString($category); }