|
3 | 3 | * Copyright 2014 Adobe
|
4 | 4 | * All Rights Reserved.
|
5 | 5 | */
|
| 6 | + |
6 | 7 | namespace Magento\CatalogSearch\Controller\Result;
|
7 | 8 |
|
| 9 | +use Magento\Catalog\Model\Product\ProductList\Toolbar; |
8 | 10 | use Magento\Framework\App\Action\HttpGetActionInterface;
|
9 | 11 | use Magento\Catalog\Model\Layer\Resolver;
|
10 | 12 | use Magento\Catalog\Model\Session;
|
@@ -88,28 +90,37 @@ public function execute()
|
88 | 90 |
|
89 | 91 | $queryText = $query->getQueryText();
|
90 | 92 |
|
91 |
| - if ($queryText != '') { |
92 |
| - $catalogSearchHelper = $this->_objectManager->get(\Magento\CatalogSearch\Helper\Data::class); |
| 93 | + if (empty($queryText)) { |
| 94 | + $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); |
| 95 | + return; |
| 96 | + } |
93 | 97 |
|
94 |
| - $getAdditionalRequestParameters = $this->getRequest()->getParams(); |
95 |
| - unset($getAdditionalRequestParameters[QueryFactory::QUERY_VAR_NAME]); |
| 98 | + // Negative ?p= value is not supported, redirect to a base version of category page. |
| 99 | + if ($this->_request->getParam(Toolbar::PAGE_PARM_NAME) < 0) { |
| 100 | + $this->getResponse()->setRedirect( |
| 101 | + $this->_url->getUrl('*/*', ['_current' => true, '_query' => [Toolbar::PAGE_PARM_NAME => null]]) |
| 102 | + ); |
| 103 | + return; |
| 104 | + } |
96 | 105 |
|
97 |
| - $handles = null; |
98 |
| - if ($query->getNumResults() == 0) { |
99 |
| - $this->_view->getPage()->initLayout(); |
100 |
| - $handles = $this->_view->getLayout()->getUpdate()->getHandles(); |
101 |
| - $handles[] = static::DEFAULT_NO_RESULT_HANDLE; |
102 |
| - } |
| 106 | + $catalogSearchHelper = $this->_objectManager->get(\Magento\CatalogSearch\Helper\Data::class); |
103 | 107 |
|
104 |
| - if (empty($getAdditionalRequestParameters) && |
105 |
| - $this->_objectManager->get(PopularSearchTerms::class)->isCacheable($queryText, $storeId) |
106 |
| - ) { |
107 |
| - $this->getCacheableResult($catalogSearchHelper, $query, $handles); |
108 |
| - } else { |
109 |
| - $this->getNotCacheableResult($catalogSearchHelper, $query, $handles); |
110 |
| - } |
| 108 | + $getAdditionalRequestParameters = $this->getRequest()->getParams(); |
| 109 | + unset($getAdditionalRequestParameters[QueryFactory::QUERY_VAR_NAME]); |
| 110 | + |
| 111 | + $handles = null; |
| 112 | + if ($query->getNumResults() == 0) { |
| 113 | + $this->_view->getPage()->initLayout(); |
| 114 | + $handles = $this->_view->getLayout()->getUpdate()->getHandles(); |
| 115 | + $handles[] = static::DEFAULT_NO_RESULT_HANDLE; |
| 116 | + } |
| 117 | + |
| 118 | + if (empty($getAdditionalRequestParameters) && |
| 119 | + $this->_objectManager->get(PopularSearchTerms::class)->isCacheable($queryText, $storeId) |
| 120 | + ) { |
| 121 | + $this->getCacheableResult($catalogSearchHelper, $query, $handles); |
111 | 122 | } else {
|
112 |
| - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); |
| 123 | + $this->getNotCacheableResult($catalogSearchHelper, $query, $handles); |
113 | 124 | }
|
114 | 125 | }
|
115 | 126 |
|
|
0 commit comments