catalogLayer = $layerResolver->get(); $this->catalogSearchData = $catalogSearchData; $this->queryFactory = $queryFactory; parent::__construct($context, $data); } /** * Retrieve query model object * * @return \Magento\Search\Model\Query */ protected function _getQuery() { return $this->queryFactory->get(); } /** * Prepare layout * * @return $this */ protected function _prepareLayout() { $title = $this->getSearchQueryText(); $this->pageConfig->getTitle()->set($title); // add Home breadcrumb $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); if ($breadcrumbs) { $breadcrumbs->addCrumb( 'home', [ 'label' => __('Home'), 'title' => __('Go to Home Page'), 'link' => $this->_storeManager->getStore()->getBaseUrl() ] )->addCrumb( 'search', ['label' => $title, 'title' => $title] ); } return parent::_prepareLayout(); } /** * Retrieve additional blocks html * * @return string */ public function getAdditionalHtml() { return $this->getLayout()->getBlock('search_result_list')->getChildHtml('additional'); } /** * Retrieve search list toolbar block * * @return ListProduct */ public function getListBlock() { return $this->getChildBlock('search_result_list'); } /** * Set search available list orders * * @return $this */ public function setListOrders() { $category = $this->catalogLayer->getCurrentCategory(); /* @var $category \Magento\Catalog\Model\Category */ $availableOrders = $category->getAvailableSortByOptions(); unset($availableOrders['position']); $availableOrders['relevance'] = __('Relevance'); $this->getListBlock()->setAvailableOrders( $availableOrders )->setDefaultDirection( 'desc' )->setDefaultSortBy( 'relevance' ); return $this; } /** * Set available view mode * * @return $this */ public function setListModes() { $test = $this->getListBlock(); $test->setModes(['grid' => __('Grid'), 'list' => __('List')]); return $this; } /** * Retrieve Search result list HTML output * * @return string */ public function getProductListHtml() { return $this->getChildHtml('search_result_list'); } /** * Retrieve loaded category collection * * @return Collection */ protected function _getProductCollection() { if (null === $this->productCollection) { $this->productCollection = $this->getListBlock()->getLoadedProductCollection(); } return $this->productCollection; } /** * Get search query text * * @return \Magento\Framework\Phrase */ public function getSearchQueryText() { return __("Search results for: '%1'", $this->catalogSearchData->getEscapedQueryText()); } /** * Retrieve search result count * * @return string */ public function getResultCount() { if (!$this->getData('result_count')) { $size = $this->_getProductCollection()->getSize(); $this->_getQuery()->saveNumResults($size); $this->setResultCount($size); } return $this->getData('result_count'); } /** * Retrieve No Result or Minimum query length Text * * @return \Magento\Framework\Phrase|string */ public function getNoResultText() { if ($this->catalogSearchData->isMinQueryLength()) { return __('Minimum Search query length is %1', $this->_getQuery()->getMinQueryLength()); } return $this->_getData('no_result_text'); } /** * Retrieve Note messages * * @return array */ public function getNoteMessages() { return $this->catalogSearchData->getNoteMessages(); } }