From 2912dc6794a3ef3cda7f1aa32055b17b64335793 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Sat, 22 Jan 2022 13:12:43 +0100 Subject: [PATCH] Display filters, and fix css for article --- app/Http/Controllers/Shop/HomeController.php | 8 ++- app/Repositories/Shop/Articles.php | 4 +- app/Repositories/Shop/TagGroups.php | 20 +++++--- .../Shop/Articles/partials/article.blade.php | 51 ++++++++++--------- .../views/Shop/Tags/partials/filter.blade.php | 12 ++++- resources/views/Shop/home.blade.php | 1 + .../views/components/form/checkbox.blade.php | 2 +- 7 files changed, 57 insertions(+), 41 deletions(-) diff --git a/app/Http/Controllers/Shop/HomeController.php b/app/Http/Controllers/Shop/HomeController.php index 097d8804..d151bb20 100644 --- a/app/Http/Controllers/Shop/HomeController.php +++ b/app/Http/Controllers/Shop/HomeController.php @@ -9,6 +9,7 @@ use App\Repositories\Shop\Articles; use App\Repositories\Shop\Categories; use App\Repositories\Shop\Offers; use App\Repositories\Shop\Tags; +use App\Repositories\Shop\TagGroups; class HomeController extends Controller { @@ -24,11 +25,8 @@ class HomeController extends Controller $data['display_by_rows'] = $input['by_rows'] ?? false; // $data['offers'] = Offers::getLast()->toArray(); $data['articles'] = Articles::getArticlesToSell(); - $data['tags'] = Tags::getWithCountOffers(); - - // $data['prices'] = $data['articles']['offers'][0]['tariff']['price_lists'][0]['price_list_values'][0]; - // dump($data); - // exit; + // $data['tags'] = Tags::getWithCountOffers(); + $data['tags'] = TagGroups::getWithTagsAndCountOffers(); return view('Shop.home', $data); } } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index b38b4be3..b8e35df3 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -64,8 +64,6 @@ class Articles public static function getArticlesToSell() { $articles = self::getArticlesWithOffers(); - // dump($articles->toArray()); - // exit; foreach ($articles as $article) { $price_lists = $article->offers[0]->tariff->price_lists->toArray(); // dump($price_lists); @@ -75,6 +73,8 @@ class Articles 'image' => $article->image, 'product_type' => $article->product_type, 'product_id' => $article->product_id, + 'product_name' => $article->product->name, + 'parent_name' => trim(str_replace($article->product->name, '', $article->name)), ]; $prices = $price_lists[0]['price_list_values'][0]; $article_nature_name = strtolower($article->article_nature->name); diff --git a/app/Repositories/Shop/TagGroups.php b/app/Repositories/Shop/TagGroups.php index a0775eb8..3b9231db 100644 --- a/app/Repositories/Shop/TagGroups.php +++ b/app/Repositories/Shop/TagGroups.php @@ -2,17 +2,11 @@ namespace App\Repositories\Shop; -use Yajra\DataTables\DataTables; - use App\Models\Shop\TagGroup; +use App\Models\Shop\Tag; class TagGroups { - public static function getDatatable() - { - $model = TagGroup::query(); - return Datatables::of($model)->make(true); - } public static function getOptions() { @@ -21,7 +15,17 @@ class TagGroups public static function getWithTagsAndCountOffers() { - return TagGroup::with('tags')->withCount(['tags.articles'])->get()->toArray(); + $tags = Tag::withCount(['articles'])->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'], + ]; + } + return $data; } public static function getTreeTags() diff --git a/resources/views/Shop/Articles/partials/article.blade.php b/resources/views/Shop/Articles/partials/article.blade.php index a57e513d..d7dc1232 100644 --- a/resources/views/Shop/Articles/partials/article.blade.php +++ b/resources/views/Shop/Articles/partials/article.blade.php @@ -2,31 +2,34 @@
...
- {{ $product_name }} - - - - -

-

-
- @if ($article['semences'] ?? false) - {{ $article['semences']['price'] ?? null }}
- @else - Indisponible - @endif - Semence -
-
- @if ($article['plants'] ?? false) - {{ $article['plants']['price'] }}
- @else - Indisponible - @endif - Plant -
+
+
+

{{ $article['parent_name'] }}

+ {{ $article['product_name'] }}
-

+
+ +
+
+ +
+
+ @if ($article['semences'] ?? false) + {{ $article['semences']['price'] ?? null }}
+ @else + Indisponible
+ @endif + Semence +
+
+ @if ($article['plants'] ?? false) + {{ $article['plants']['price'] }}
+ @else + Indisponible
+ @endif + Plant +
+
diff --git a/resources/views/Shop/Tags/partials/filter.blade.php b/resources/views/Shop/Tags/partials/filter.blade.php index 7e5f68ec..8dfc12ad 100644 --- a/resources/views/Shop/Tags/partials/filter.blade.php +++ b/resources/views/Shop/Tags/partials/filter.blade.php @@ -1,2 +1,12 @@ -@foreach ($tags as $tag) +@foreach ($tags as $group) +
{{ $group['name'] }}
+ @foreach ($group['tags'] as $tag) +
+ @include('components.form.checkbox', [ + 'name' => 'tag[]', + 'val' => $tag['id'], + ]) + {{ $tag['name'] }} ({{ $tag['count'] }}) +
+ @endforeach @endforeach \ No newline at end of file diff --git a/resources/views/Shop/home.blade.php b/resources/views/Shop/home.blade.php index 1c23495c..8baa3b6f 100644 --- a/resources/views/Shop/home.blade.php +++ b/resources/views/Shop/home.blade.php @@ -5,6 +5,7 @@ @section('content')
+ @include('Shop.Tags.partials.filter')
@if ($display_by_rows ?? false) diff --git a/resources/views/components/form/checkbox.blade.php b/resources/views/components/form/checkbox.blade.php index 357279d9..65eb77db 100644 --- a/resources/views/components/form/checkbox.blade.php +++ b/resources/views/components/form/checkbox.blade.php @@ -1,4 +1,4 @@ - \ No newline at end of file