From a70e8c39cfb2440dafc3ce6c10c59c677cb14b69 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Mon, 9 May 2022 22:33:18 +0200 Subject: [PATCH] modify filter calculation --- app/Repositories/Shop/TagGroups.php | 16 +++++---- .../views/Shop/Tags/partials/filter.blade.php | 34 +++++++++++-------- resources/views/Shop/layout/layout.blade.php | 2 -- .../Shop/layout/partials/header-nav.blade.php | 10 +++++- .../layout/partials/header-profile.blade.php | 8 +++-- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/app/Repositories/Shop/TagGroups.php b/app/Repositories/Shop/TagGroups.php index 316bffda..8f3804c2 100644 --- a/app/Repositories/Shop/TagGroups.php +++ b/app/Repositories/Shop/TagGroups.php @@ -16,15 +16,19 @@ class TagGroups public static function getWithTagsAndCountOffers($category_id = false) { - $tags = Tag::withCount(['articles'])->get()->toArray(); + $tags = Tag::withCount(['articles' => function($query) use ($category_id) { + $query->byCategory($category_id); + }])->get()->toArray(); $tag_groups = TagGroup::pluck('name', 'id')->toArray(); foreach ($tags as $tag) { $data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']]; - $data[$tag['tag_group_id']]['tags'][] = [ - 'id' => $tag['id'], - 'name' => $tag['name'], - 'count' => $tag['articles_count'], - ]; + if ($tag['articles_count']) { + $data[$tag['tag_group_id']]['tags'][] = [ + 'id' => $tag['id'], + 'name' => $tag['name'], + 'count' => $tag['articles_count'], + ]; + } } return $data; } diff --git a/resources/views/Shop/Tags/partials/filter.blade.php b/resources/views/Shop/Tags/partials/filter.blade.php index 829db31a..932ea10e 100644 --- a/resources/views/Shop/Tags/partials/filter.blade.php +++ b/resources/views/Shop/Tags/partials/filter.blade.php @@ -8,20 +8,22 @@ @foreach ($tags as $tag_group_id => $group) - @component('components.layout.box-collapse', [ - 'title' => $group['name'], - 'id' => 'tag_group_' . $tag_group_id, - ]) - @foreach ($group['tags'] as $tag) -
- @include('components.form.checkbox', [ - 'name' => 'tag[]', - 'val' => $tag['id'], - ]) - {{ $tag['name'] }} ({{ $tag['count'] }}) -
- @endforeach - @endcomponent + @if ($group['tags'] ?? false) + @component('components.layout.box-collapse', [ + 'title' => $group['name'], + 'id' => 'tag_group_' . $tag_group_id, + ]) + @foreach ($group['tags'] as $tag) +
+ @include('components.form.checkbox', [ + 'name' => 'tag[]', + 'val' => $tag['id'], + ]) + {{ $tag['name'] }} ({{ $tag['count'] }}) +
+ @endforeach + @endcomponent + @endif @endforeach @@ -33,7 +35,9 @@ @endpush \ No newline at end of file diff --git a/resources/views/Shop/layout/layout.blade.php b/resources/views/Shop/layout/layout.blade.php index 0829a778..b8f07b08 100644 --- a/resources/views/Shop/layout/layout.blade.php +++ b/resources/views/Shop/layout/layout.blade.php @@ -59,8 +59,6 @@