|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | +declare(strict_types=1); |
| 7 | + |
6 | 8 | namespace Magento\Search\Controller\Term;
|
7 | 9 |
|
8 |
| -use Magento\Framework\App\Action\Action; |
9 |
| -use Magento\Framework\App\Action\Context; |
| 10 | +use Magento\Framework\App\Action\HttpGetActionInterface; |
10 | 11 | use Magento\Framework\App\Config\ScopeConfigInterface;
|
11 |
| -use Magento\Framework\App\RequestInterface; |
| 12 | +use Magento\Framework\Controller\Result\ForwardFactory as ResultForwardFactory; |
| 13 | +use Magento\Framework\View\Result\PageFactory as ResultPageFactory; |
12 | 14 | use Magento\Store\Model\ScopeInterface;
|
13 |
| -use Magento\Framework\Controller\ResultFactory; |
14 | 15 |
|
15 |
| -class Popular extends Action |
| 16 | +/** |
| 17 | + * Popular search terms page |
| 18 | + */ |
| 19 | +class Popular implements HttpGetActionInterface |
16 | 20 | {
|
| 21 | + private const XML_PATH_SEO_SEARCH_TERMS = 'catalog/seo/search_terms'; |
| 22 | + |
17 | 23 | /**
|
18 |
| - * @var \Magento\Framework\App\Config\ScopeConfigInterface |
| 24 | + * @var ResultForwardFactory |
19 | 25 | */
|
20 |
| - protected $scopeConfig; |
| 26 | + private $resultForwardFactory; |
21 | 27 |
|
22 | 28 | /**
|
23 |
| - * @param \Magento\Framework\App\Action\Context $context |
24 |
| - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
| 29 | + * @var ResultPageFactory |
25 | 30 | */
|
26 |
| - public function __construct(Context $context, ScopeConfigInterface $scopeConfig) |
27 |
| - { |
| 31 | + private $resultPageFactory; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var ScopeConfigInterface |
| 35 | + */ |
| 36 | + private $scopeConfig; |
| 37 | + |
| 38 | + /** |
| 39 | + * @param ResultForwardFactory $resultForwardFactory |
| 40 | + * @param ResultPageFactory $resultPageFactory |
| 41 | + * @param ScopeConfigInterface $scopeConfig |
| 42 | + */ |
| 43 | + public function __construct( |
| 44 | + ResultForwardFactory $resultForwardFactory, |
| 45 | + ResultPageFactory $resultPageFactory, |
| 46 | + ScopeConfigInterface $scopeConfig |
| 47 | + ) { |
| 48 | + $this->resultForwardFactory = $resultForwardFactory; |
| 49 | + $this->resultPageFactory = $resultPageFactory; |
28 | 50 | $this->scopeConfig = $scopeConfig;
|
29 |
| - parent::__construct($context); |
30 | 51 | }
|
31 | 52 |
|
32 | 53 | /**
|
33 |
| - * Dispatch request |
34 |
| - * |
35 |
| - * @param \Magento\Framework\App\RequestInterface $request |
36 |
| - * @return \Magento\Framework\App\ResponseInterface |
37 |
| - * @throws \Magento\Framework\Exception\NotFoundException |
| 54 | + * @inheritDoc |
38 | 55 | */
|
39 |
| - public function dispatch(RequestInterface $request) |
| 56 | + public function execute() |
40 | 57 | {
|
41 |
| - $searchTerms = $this->scopeConfig->getValue( |
42 |
| - 'catalog/seo/search_terms', |
43 |
| - ScopeInterface::SCOPE_STORE |
44 |
| - ); |
45 |
| - if (!$searchTerms) { |
46 |
| - $this->_redirect('noroute'); |
47 |
| - $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); |
| 58 | + if (!$this->checkEnabledSearchTerms()) { |
| 59 | + $resultForward = $this->resultForwardFactory->create(); |
| 60 | + $resultForward->forward('noroute'); |
| 61 | + |
| 62 | + return $resultForward; |
48 | 63 | }
|
49 |
| - return parent::dispatch($request); |
| 64 | + |
| 65 | + return $this->resultPageFactory->create(); |
50 | 66 | }
|
51 | 67 |
|
52 | 68 | /**
|
53 |
| - * @return \Magento\Framework\View\Result\Page |
| 69 | + * Check if search terms are enabled |
| 70 | + * |
| 71 | + * @return bool |
54 | 72 | */
|
55 |
| - public function execute() |
| 73 | + private function checkEnabledSearchTerms(): bool |
56 | 74 | {
|
57 |
| - /** @var \Magento\Framework\View\Result\Page $resultPage */ |
58 |
| - $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); |
59 |
| - return $resultPage; |
| 75 | + return $this->scopeConfig->isSetFlag( |
| 76 | + self::XML_PATH_SEO_SEARCH_TERMS, |
| 77 | + ScopeInterface::SCOPE_STORE |
| 78 | + ); |
60 | 79 | }
|
61 | 80 | }
|
0 commit comments