Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions resources/views/category/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

@section('title', $category->meta_title ?: $category->name)
@section('description', $category->meta_description)
@section('canonical', url($category->url))
@if ($category->is_anchor)
@php
$total = $category->listingProducts()->count()
@endphp
@include('rapidez::layouts.partials.head.pagination', [
'url' => url($category->url),
'total' => $total,
'perPage' => Rapidez::config('catalog/frontend/grid_per_page'),
])
@else
@section('canonical', url($category->url))
@endif
@include('rapidez::layouts.partials.head.hreflang', ['alternates' => $category->alternates])

@section('content')
Expand All @@ -12,7 +23,7 @@
<h1 class="text-2xl font-medium mb-5">{{ $category->name }}</h1>

@if ($category->is_anchor)
@if (!$category->products()->exists())
@if ($total == 0)
@include('rapidez::listing.partials.no-products')
@else
<x-rapidez::listing
Expand Down
16 changes: 16 additions & 0 deletions resources/views/layouts/partials/head/pagination.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@php
$currentPage = max((int) request('page', 1), 1);
$lastPage = max(ceil($total / $perPage), 1);
@endphp

@section('canonical', $currentPage === 1 ? $url : $url . '?page=' . $currentPage)

@push('head')
@if ($currentPage > 1)
<link rel="prev" href="{{ $url . '?page=' . ($currentPage - 1) }}" />
@endif

@if ($currentPage < $lastPage)
<link rel="next" href="{{ $url . '?page=' . ($currentPage + 1) }}" />
@endif
@endpush
9 changes: 9 additions & 0 deletions src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,6 +76,14 @@ public function products(): HasManyThrough
);
}

public function listingProducts(): HasManyThrough
{
return $this->products()->whereInAttribute('visibility', [
Visibility::Catalog->value,
Visibility::Both->value,
]);
}

public function categoryProducts(): HasMany
{
return $this->hasMany(
Expand Down
Loading