From 5e161745bb0df3add28fec3d941687a805059271 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Tue, 12 Sep 2023 23:27:56 +0200 Subject: [PATCH] adapt display of article natures by disponibility of offers in shelve --- .../Controllers/Shop/CategoryController.php | 25 +++++----- .../Shelves/partials/category_add.blade.php | 47 ++++--------------- 2 files changed, 20 insertions(+), 52 deletions(-) diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php index 47e72a53..8cbbf487 100644 --- a/app/Http/Controllers/Shop/CategoryController.php +++ b/app/Http/Controllers/Shop/CategoryController.php @@ -21,31 +21,28 @@ class CategoryController extends Controller public function show(Request $request, $categoryId, $articleNatureId = false) { + $productTypes = Articles::getProductTypesWithOffers([ + 'category_id' => $categoryId, + ]); + + $articleNatures = Articles::getArticleNaturesWithOffers([ + 'category_id' => $categoryId, + ]); + if ($articleNatureId) { $productType = ArticleNatures::getProductType($articleNatureId); dump($productType); exit; } else { $articleNature = $request->input('article_nature'); - if (!$articleNature) { - $articleNatures = Articles::getArticleNaturesWithOffers([ - 'category_id' => $categoryId, - ]); + if (! $articleNature) { if (count($articleNatures) === 1) { $articleNature = $articleNatures[0]; } else { $articleNature = 'semences'; } - $productTypes = Articles::getProductTypesWithOffers([ - 'category_id' => $categoryId, - ]); - if (count($productTypes) === 1) { - $productType = $productTypes[0]; - } - } else { - $productType = ArticleNatures::getProductTypeBySlug($articleNature); } - + $productType = ArticleNatures::getProductTypeBySlug($articleNature); $articleNatureId = ArticleNatures::getIdBySlug($articleNature); } $data = [ @@ -65,6 +62,8 @@ class CategoryController extends Controller ]), 'tags' => TagGroups::getWithTagsAndCountOffers($categoryId), ]; + // dump($data); + // exit; return view('Shop.Shelves.shelve', $data); } diff --git a/resources/views/Shop/Shelves/partials/category_add.blade.php b/resources/views/Shop/Shelves/partials/category_add.blade.php index e767d4f8..539c9695 100644 --- a/resources/views/Shop/Shelves/partials/category_add.blade.php +++ b/resources/views/Shop/Shelves/partials/category_add.blade.php @@ -1,45 +1,14 @@
-
-
-
- + @foreach ($article_natures as $nature) +
+
+
+ +
+
Semences
-
Semences
-
-
-
-
- -
-
Plants
-
-
-
-
-
- -
-
Légumes
-
-
-
- -
-
- @include('components.form.button', [ - 'data_id' => 'semences', - 'icon' => 'fa-leaf', - 'class' => 'products bg-yellow yellow-dark' . (($article_nature == 'semences') ? ' d-none' : ''), - 'title' => 'Par semences', - ]) - @include('components.form.button', [ - 'data_id' => 'plants', - 'icon' => 'fa-seedling', - 'class' => 'products bg-green text-white' . (($article_nature == 'plants') ? ' d-none' : ''), - 'title' => 'Par plants', - ]) -
+ @endforeach
@push('js')