_storeManager = $storeManager; $this->_catalogSession = $catalogSession; $this->_queryFactory = $queryFactory; $this->layerResolver = $layerResolver; $this->_jsonHelper = $jsonHelper; $this->_moduleHelper = $moduleHelper; $this->_helper = $helper; } /** * Display search result * * @return void */ public function execute() { $this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH); /* @var $query \Magento\Search\Model\Query */ $query = $this->_queryFactory->get(); $query->setStoreId($this->_storeManager->getStore()->getId()); if ($query->getQueryText() != '') { if ($this->_helper->isMinQueryLength()) { $query->setId(0)->setIsActive(1)->setIsProcessed(1); } else { $query->saveIncrementalPopularity(); if ($query->getRedirect()) { $this->getResponse()->setRedirect($query->getRedirect()); return; } } $this->_helper->checkNotes(); if ($this->_moduleHelper->isEnabled() && $this->getRequest()->isAjax()) { $navigation = $this->_view->getLayout()->getBlock('catalogsearch.leftnav'); $products = $this->_view->getLayout()->getBlock('search.result'); $result = ['products' => $products->toHtml(), 'navigation' => $navigation->toHtml()]; $this->getResponse()->representJson($this->_jsonHelper->jsonEncode($result)); } else { $this->_view->loadLayout(); $this->_view->renderLayout(); } } else { $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); } } }