24 private $storeManager;
31 private $catalogSearchHelper;
36 private $queryFactory;
41 private $resultJsonFactory;
52 HelperData $catalogSearchHelper,
57 parent::__construct($context);
59 $this->catalogSearchHelper = $catalogSearchHelper;
60 $this->queryFactory = $queryFactory;
61 $this->resultJsonFactory = $resultJsonFactory;
72 $query = $this->queryFactory->get();
74 $query->setStoreId($this->storeManager->getStore()->getId());
76 if (
$query->getQueryText() !=
'') {
78 if ($this->catalogSearchHelper->isMinQueryLength()) {
79 $query->setId(0)->setIsActive(1)->setIsProcessed(1);
81 $query->saveIncrementalPopularity();
83 $responseContent = [
'success' =>
true,
'error_message' =>
''];
84 }
catch (\
Magento\Framework\Exception\LocalizedException $e) {
85 $responseContent = [
'success' =>
false,
'error_message' => $e];
88 $responseContent = [
'success' =>
false,
'error_message' =>
__(
'Search term is empty')];
92 $resultJson = $this->resultJsonFactory->create();
93 return $resultJson->setData($responseContent);
__construct(Context $context, HelperData $catalogSearchHelper, StoreManagerInterface $storeManager, QueryFactory $queryFactory, JsonFactory $resultJsonFactory)