20 private $queryFactory;
30 parent::__construct($context);
31 $this->queryFactory = $queryFactory;
45 $model = $this->loadQuery();
49 $this->messageManager->addSuccessMessage(
__(
'You saved the search term.'));
50 }
catch (LocalizedException $e) {
51 $this->messageManager->addErrorMessage($e->getMessage());
52 return $this->proceedToEdit(
$data);
53 }
catch (\Exception $e) {
54 $this->messageManager->addExceptionMessage(
56 __(
'Something went wrong while saving the search query.')
58 return $this->proceedToEdit(
$data);
64 return $redirectResult->setPath(
'search/*');
73 private function loadQuery()
76 $queryText = $this->
getRequest()->getPost(
'query_text',
false);
77 $queryId = $this->
getRequest()->getPost(
'query_id',
null);
80 $model = $this->queryFactory->create();
84 $model->loadByQueryText($queryText);
86 throw new \Magento\Framework\Exception\LocalizedException(
87 __(
'You already have an identical search term query.')
91 if ($queryId && !
$model->getId()) {
103 private function proceedToEdit(
$data)
108 return $redirectResult->setPath(
'search/*/edit', [
'id' => $this->
getRequest()->getPost(
'query_id',
null)]);
__construct(Context $context, QueryFactory $queryFactory)