diff --git a/classes/controller/ProductListingFrontController.php b/classes/controller/ProductListingFrontController.php index 309800058179b..94ac81d7040c3 100644 --- a/classes/controller/ProductListingFrontController.php +++ b/classes/controller/ProductListingFrontController.php @@ -418,17 +418,33 @@ protected function getTemplateVarPagination( $itemsShownFrom = ($query->getResultsPerPage() * ($query->getPage() - 1)) + 1; $itemsShownTo = $query->getResultsPerPage() * $query->getPage(); + $pages = array_map(function ($link) { + $link['url'] = $this->updateQueryString(array( + 'page' => $link['page'] > 1 ? $link['page'] : null, + )); + + return $link; + }, $pagination->buildLinks()); + + //Filter next/previous link on first/last page + $pages = array_filter($pages, function ($page) use ($pagination) { + if ('previous' === $page['type'] && 1 === $pagination->getPage()) { + return false; + } + if ('next' === $page['type'] && $pagination->getPagesCount() === $pagination->getPage()) { + return false; + } + + return true; + }); + return array( 'total_items' => $totalItems, 'items_shown_from' => $itemsShownFrom, 'items_shown_to' => ($itemsShownTo <= $totalItems) ? $itemsShownTo : $totalItems, - 'pages' => array_map(function ($link) { - $link['url'] = $this->updateQueryString(array( - 'page' => $link['page'], - )); - - return $link; - }, $pagination->buildLinks()), + 'current_page' => $pagination->getPage(), + 'pages_count' => $pagination->getPagesCount(), + 'pages' => $pages, // Compare to 3 because there are the next and previous links 'should_be_displayed' => (count($pagination->buildLinks()) > 3), ); diff --git a/controllers/front/listing/CategoryController.php b/controllers/front/listing/CategoryController.php index 4d92d8e142d75..166a11d098faf 100644 --- a/controllers/front/listing/CategoryController.php +++ b/controllers/front/listing/CategoryController.php @@ -52,7 +52,22 @@ public function canonicalRedirection($canonicalURL = '') public function getCanonicalURL() { - return $this->context->link->getCategoryLink($this->category); + $canonicalUrl = $this->context->link->getCategoryLink($this->category); + $parsedUrl = parse_url($canonicalUrl); + if (isset($parsedUrl['query'])) { + parse_str($parsedUrl['query'], $params); + } else { + $params = array(); + } + $page = (int) Tools::getValue('page'); + if ($page > 1) { + $params['page'] = $page; + } else { + unset($params['page']); + } + $canonicalUrl = http_build_url($parsedUrl, ['query' => http_build_query($params)]); + + return $canonicalUrl; } /** diff --git a/themes/classic/templates/_partials/pagination.tpl b/themes/classic/templates/_partials/pagination.tpl index 1631dcaab57c0..7d0091cda091f 100644 --- a/themes/classic/templates/_partials/pagination.tpl +++ b/themes/classic/templates/_partials/pagination.tpl @@ -34,7 +34,8 @@ {if $pagination.should_be_displayed}