From 9b95db889aa0f19aeee4f6fc00432a5ccfc727ad Mon Sep 17 00:00:00 2001 From: rogerdz Date: Wed, 3 Sep 2025 16:46:12 +0000 Subject: [PATCH] Robots meta tags for category page with url parameters --- .../Catalog/Controller/Category/View.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/code/Magento/Catalog/Controller/Category/View.php b/app/code/Magento/Catalog/Controller/Category/View.php index da7c5326587e3..d84fc4b7a143a 100644 --- a/app/code/Magento/Catalog/Controller/Category/View.php +++ b/app/code/Magento/Catalog/Controller/Category/View.php @@ -200,6 +200,7 @@ protected function _initCategory() * Category view action * * @throws NoSuchEntityException + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { @@ -251,6 +252,10 @@ public function execute() if ($this->shouldRedirectOnToolbarAction()) { $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); } + + if ($this->shouldNoIndexNoFollow()) { + $page->getConfig()->setRobots('NOINDEX,NOFOLLOW'); + } return $page; } elseif (!$this->getResponse()->isRedirect()) { $result = $this->resultForwardFactory->create()->forward('noroute'); @@ -315,4 +320,20 @@ private function shouldRedirectOnToolbarAction(): bool Toolbar::LIMIT_PARAM_NAME ], array_keys($params))) === false; } + + /** + * Checks for robots meta tags + * + * @return bool + */ + private function shouldNoIndexNoFollow(): bool + { + $params = $this->getRequest()->getParams(); + + return empty(array_diff(array_keys($params), [ + Toolbar::LIMIT_PARAM_NAME, + Toolbar::PAGE_PARM_NAME, + 'id' + ])) === false; + } }