From a9432bd3c198fc1400a2bdcb94d27fed410e2cd1 Mon Sep 17 00:00:00 2001 From: ludo Date: Tue, 17 Oct 2023 17:47:25 +0200 Subject: [PATCH] add filter not collapsed if filter is on --- app/Http/Controllers/Shop/CategoryController.php | 2 +- app/Repositories/Shop/TagGroups.php | 15 +++++++++++++-- .../views/Shop/Tags/partials/filter.blade.php | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php index 35520bfb..ff276173 100644 --- a/app/Http/Controllers/Shop/CategoryController.php +++ b/app/Http/Controllers/Shop/CategoryController.php @@ -53,7 +53,7 @@ class CategoryController extends Controller 'tags' => TagGroups::getWithTagsAndCountOffers($categoryId), ]; - dump($data); + // dump($data); // exit; return view('Shop.Shelves.shelve', $data); } diff --git a/app/Repositories/Shop/TagGroups.php b/app/Repositories/Shop/TagGroups.php index d0b09dc1..209fb721 100644 --- a/app/Repositories/Shop/TagGroups.php +++ b/app/Repositories/Shop/TagGroups.php @@ -17,12 +17,12 @@ class TagGroups { $data = []; $tags = Tag::withCountArticlesByCategory($category_id)->get()->toArray(); - $tag_groups = TagGroup::pluck('name', 'id')->toArray(); + $tagGroups = TagGroup::pluck('name', 'id')->toArray(); foreach ($tags as $tag) { if (! $tag['articles_count']) { continue; } - $data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']]; + $data[$tag['tag_group_id']]['name'] = $tagGroups[$tag['tag_group_id']]; $data[$tag['tag_group_id']]['tags'][] = [ 'id' => $tag['id'], 'name' => $tag['name'], @@ -33,6 +33,17 @@ class TagGroups return $data; } + public static function isTagGroupHaveSelected($tagsSelected, $tags) + { + foreach ($tags as $tag) { + if (in_array($tag['id'], $tagsSelected)) { + return false; + } + } + + return true; + } + public static function getTreeTags() { $items = TagGroup::with('tags')->get(); diff --git a/resources/views/Shop/Tags/partials/filter.blade.php b/resources/views/Shop/Tags/partials/filter.blade.php index aec39b6d..2dbcd923 100644 --- a/resources/views/Shop/Tags/partials/filter.blade.php +++ b/resources/views/Shop/Tags/partials/filter.blade.php @@ -6,6 +6,7 @@ @component('components.layout.box-collapse', [ 'title' => $group['name'], 'id' => 'tag_group_' . $tag_group_id, + 'collapsed' => App\Repositories\Shop\TagGroups::isTagGroupHaveSelected($tags_selected, $group['tags']), ]) @foreach ($group['tags'] as $tag)