From 26690772850b8fa033b6538335fa098042a71c93 Mon Sep 17 00:00:00 2001 From: jimmy Date: Tue, 2 Jun 2026 09:46:22 +0200 Subject: [PATCH 1/4] add canonical pagination links --- resources/views/category/overview.blade.php | 12 ++++++++++-- .../layouts/partials/head/pagination.blade.php | 17 +++++++++++++++++ src/Models/Category.php | 8 ++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 resources/views/layouts/partials/head/pagination.blade.php diff --git a/resources/views/category/overview.blade.php b/resources/views/category/overview.blade.php index 01db3da39..fce68068f 100644 --- a/resources/views/category/overview.blade.php +++ b/resources/views/category/overview.blade.php @@ -2,7 +2,15 @@ @section('title', $category->meta_title ?: $category->name) @section('description', $category->meta_description) -@section('canonical', url($category->url)) +@if ($category->is_anchor) + @include('rapidez::layouts.partials.head.pagination', [ + 'url' => url($category->url), + 'total' => $category->listingProducts()->count(), + 'perPage' => Rapidez::config('catalog/frontend/grid_per_page', 12), + ]) +@else + @section('canonical', url($category->url)) +@endif @include('rapidez::layouts.partials.head.hreflang', ['alternates' => $category->alternates]) @section('content') @@ -12,7 +20,7 @@

{{ $category->name }}

@if ($category->is_anchor) - @if (!$category->products()->exists()) + @if (!$category->listingProducts()->exists()) @include('rapidez::listing.partials.no-products') @else $page > 0 ? $url . '?' . http_build_query(['page' => $page]) : $url; +@endphp + +@section('canonical', $pageUrl($currentPage)) + +@push('head') + @if ($currentPage > 0) + + @endif + + @if ($currentPage < $lastPage) + + @endif +@endpush diff --git a/src/Models/Category.php b/src/Models/Category.php index ccdce3472..34dcd95eb 100644 --- a/src/Models/Category.php +++ b/src/Models/Category.php @@ -76,6 +76,14 @@ public function products(): HasManyThrough ); } + public function listingProducts(): HasManyThrough + { + return $this->products()->whereInAttribute('visibility', [ + Product::VISIBILITY_IN_CATALOG, + Product::VISIBILITY_BOTH, + ]); + } + public function categoryProducts(): HasMany { return $this->hasMany( From 0e7394d5c6a69d6fa6058fbfe4c69038d791615f Mon Sep 17 00:00:00 2001 From: jimmy Date: Tue, 2 Jun 2026 12:02:40 +0200 Subject: [PATCH 2/4] small fixes --- resources/views/category/overview.blade.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/views/category/overview.blade.php b/resources/views/category/overview.blade.php index fce68068f..66d16e8be 100644 --- a/resources/views/category/overview.blade.php +++ b/resources/views/category/overview.blade.php @@ -3,10 +3,13 @@ @section('title', $category->meta_title ?: $category->name) @section('description', $category->meta_description) @if ($category->is_anchor) + @php + $total = $category->listingProducts()->count() + @endphp @include('rapidez::layouts.partials.head.pagination', [ 'url' => url($category->url), - 'total' => $category->listingProducts()->count(), - 'perPage' => Rapidez::config('catalog/frontend/grid_per_page', 12), + 'total' => $total, + 'perPage' => Rapidez::config('catalog/frontend/grid_per_page'), ]) @else @section('canonical', url($category->url)) @@ -20,7 +23,7 @@

{{ $category->name }}

@if ($category->is_anchor) - @if (!$category->listingProducts()->exists()) + @if ($total == 0) @include('rapidez::listing.partials.no-products') @else Date: Wed, 10 Jun 2026 14:53:15 +0200 Subject: [PATCH 3/4] fix pagination logic and update canonical URL generation --- .../layouts/partials/head/pagination.blade.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/resources/views/layouts/partials/head/pagination.blade.php b/resources/views/layouts/partials/head/pagination.blade.php index 67ea84337..1925337f9 100644 --- a/resources/views/layouts/partials/head/pagination.blade.php +++ b/resources/views/layouts/partials/head/pagination.blade.php @@ -1,17 +1,16 @@ @php - $currentPage = max((int) request('page', 0), 0); - $lastPage = max((int) ceil($total / max((int) $perPage, 1)) - 1, 0); - $pageUrl = fn (int $page) => $page > 0 ? $url . '?' . http_build_query(['page' => $page]) : $url; + $currentPage = max((int) request('page', 1), 1); + $lastPage = max(ceil($total / $perPage), 1); @endphp -@section('canonical', $pageUrl($currentPage)) +@section('canonical', $currentPage === 1 ? $url : $url . '?page=' . $currentPage) @push('head') - @if ($currentPage > 0) - + @if ($currentPage > 1) + @endif @if ($currentPage < $lastPage) - + @endif @endpush From 8ed3c6fa11b208844c8f4a71f0b0854e2718c428 Mon Sep 17 00:00:00 2001 From: jimmy Date: Wed, 10 Jun 2026 15:01:48 +0200 Subject: [PATCH 4/4] update constants --- src/Models/Category.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Models/Category.php b/src/Models/Category.php index 2e6ff0dbf..349b42a31 100644 --- a/src/Models/Category.php +++ b/src/Models/Category.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Rapidez\Core\Enums\EntityType; +use Rapidez\Core\Enums\Visibility; use Rapidez\Core\Facades\Rapidez; use Rapidez\Core\Models\Scopes\Category\IsActiveScope; use Rapidez\Core\Models\Traits\HasAlternatesThroughRewrites; @@ -78,8 +79,8 @@ public function products(): HasManyThrough public function listingProducts(): HasManyThrough { return $this->products()->whereInAttribute('visibility', [ - Product::VISIBILITY_IN_CATALOG, - Product::VISIBILITY_BOTH, + Visibility::Catalog->value, + Visibility::Both->value, ]); }