diff --git a/vendor/magento/module-catalog/Controller/Category/View.php b/vendor/magento/module-catalog/Controller/Category/View.php index e448be9a1df..3d031956b55 100644 --- a/vendor/magento/module-catalog/Controller/Category/View.php +++ b/vendor/magento/module-catalog/Controller/Category/View.php @@ -13,6 +13,7 @@ use Magento\Catalog\Model\Category\Attribute\LayoutUpdateManager; use Magento\Catalog\Model\Design; use Magento\Catalog\Model\Layer\Resolver; use Magento\Catalog\Model\Product\ProductList\ToolbarMemorizer; +use Magento\Catalog\Model\Product\ProductList\Toolbar; use Magento\Catalog\Model\Session; use Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator; use Magento\Framework\App\Action\Action; @@ -22,7 +23,7 @@ use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\App\ActionInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Controller\Result\ForwardFactory; -use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Controller\ResultFactory; use Magento\Framework\DataObject; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; @@ -214,6 +215,7 @@ class View extends Action implements HttpGetActionInterface, HttpPostActionInter if ($this->_request->getParam(ActionInterface::PARAM_NAME_URL_ENCODED)) { return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl()); } + $category = $this->_initCategory(); if ($category) { $this->layerResolver->create(Resolver::CATALOG_LAYER_CATEGORY); @@ -250,6 +252,9 @@ class View extends Action implements HttpGetActionInterface, HttpPostActionInter ->addBodyClass('categorypath-' . $this->categoryUrlPathGenerator->getUrlPath($category)) ->addBodyClass('category-' . $category->getUrlKey()); + if ($this->shouldRedirectOnToolbarAction()) { + $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); + } return $page; } elseif (!$this->getResponse()->isRedirect()) { $result = $this->resultForwardFactory->create()->forward('noroute'); @@ -297,4 +302,21 @@ class View extends Action implements HttpGetActionInterface, HttpPostActionInter $page->addPageLayoutHandles($settings->getPageLayoutHandles()); } } + + /** + * Checks for toolbar actions + * + * @return bool + */ + private function shouldRedirectOnToolbarAction(): bool + { + $params = $this->getRequest()->getParams(); + + return $this->toolbarMemorizer->isMemorizingAllowed() && empty(array_intersect([ + Toolbar::ORDER_PARAM_NAME, + Toolbar::DIRECTION_PARAM_NAME, + Toolbar::MODE_PARAM_NAME, + Toolbar::LIMIT_PARAM_NAME + ], array_keys($params))) === false; + } }