Popular.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Search\Controller\Term;
  7. use Magento\Framework\App\Action\Action;
  8. use Magento\Framework\App\Action\Context;
  9. use Magento\Framework\App\Config\ScopeConfigInterface;
  10. use Magento\Framework\App\RequestInterface;
  11. use Magento\Store\Model\ScopeInterface;
  12. use Magento\Framework\Controller\ResultFactory;
  13. class Popular extends Action
  14. {
  15. /**
  16. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  17. */
  18. protected $scopeConfig;
  19. /**
  20. * @param \Magento\Framework\App\Action\Context $context
  21. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  22. */
  23. public function __construct(Context $context, ScopeConfigInterface $scopeConfig)
  24. {
  25. $this->scopeConfig = $scopeConfig;
  26. parent::__construct($context);
  27. }
  28. /**
  29. * Dispatch request
  30. *
  31. * @param \Magento\Framework\App\RequestInterface $request
  32. * @return \Magento\Framework\App\ResponseInterface
  33. * @throws \Magento\Framework\Exception\NotFoundException
  34. */
  35. public function dispatch(RequestInterface $request)
  36. {
  37. $searchTerms = $this->scopeConfig->getValue(
  38. 'catalog/seo/search_terms',
  39. ScopeInterface::SCOPE_STORE
  40. );
  41. if (!$searchTerms) {
  42. $this->_redirect('noroute');
  43. $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
  44. }
  45. return parent::dispatch($request);
  46. }
  47. /**
  48. * @return \Magento\Framework\View\Result\Page
  49. */
  50. public function execute()
  51. {
  52. /** @var \Magento\Framework\View\Result\Page $resultPage */
  53. $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
  54. return $resultPage;
  55. }
  56. }