Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * @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());
 }
Esempio n. 4
0
 /**
  * Retrieve query model object
  *
  * @return \Magento\CatalogSearch\Model\Query
  */
 protected function _getQuery()
 {
     return $this->_catalogSearchData->getQuery();
 }
Esempio n. 5
0
 /**
  * @param \Magento\Catalog\Model\Category $category
  * @return string|void
  */
 public function toString($category)
 {
     return 'Q_' . $this->helper->getQuery()->getId() . '_' . parent::toString($category);
 }