From 79c717ae6c9c512391c9151121261dbedb015e44 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Mon, 13 Jun 2022 23:29:05 +0200 Subject: [PATCH] [WIP] begin of new display for article, shelves --- .../Controllers/Shop/CategoryController.php | 9 ++- app/Http/Controllers/Shop/HomeController.php | 2 +- app/Models/Shop/Article.php | 18 ++++++ app/Repositories/Shop/Articles.php | 12 ++-- app/Repositories/Shop/Homepages.php | 5 ++ .../Shop/Articles/partials/article.blade.php | 28 +-------- .../partials/article_botanic.blade.php | 22 +++++++ .../partials/article_merchandise.blade.php | 12 ++++ .../Articles/partials/article_rows.blade.php | 35 ++--------- .../partials/article_rows_botanic.blade.php | 26 ++++++++ .../article_rows_merchandise.blade.php | 13 ++++ .../Shelves/partials/category_add.blade.php | 20 ++++--- resources/views/Shop/Shelves/shelve.blade.php | 59 +++++++++++-------- 13 files changed, 163 insertions(+), 98 deletions(-) create mode 100644 resources/views/Shop/Articles/partials/article_botanic.blade.php create mode 100644 resources/views/Shop/Articles/partials/article_merchandise.blade.php create mode 100644 resources/views/Shop/Articles/partials/article_rows_botanic.blade.php create mode 100644 resources/views/Shop/Articles/partials/article_rows_merchandise.blade.php diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php index 14af9389..1430d6fd 100644 --- a/app/Http/Controllers/Shop/CategoryController.php +++ b/app/Http/Controllers/Shop/CategoryController.php @@ -20,16 +20,19 @@ class CategoryController extends Controller return $dataTable->render('Shop.Categories.list'); } - public function show($category_id, $by_rows = false) + public function show(Request $request, $category_id) { $data = self::init(); - $data['display_by_rows'] = $by_rows; $data['category'] = Categories::getFull($category_id); $data['breadcrumb'] = Categories::getAncestorsByCategory($category_id); - $data['tags_selected'] = request()->input('tags') ?? []; + $data['display_by_rows'] = $request->input('display_by_rows') ?? false; + $data['product_type'] = $request->input('product_type') ?? 'botanic'; + $data['tags_selected'] = $request->input('tags') ?? []; + $data['articles'] = Articles::getArticlesToSell([ 'category_id' => $category_id, 'tags' => $data['tags_selected'], + 'product_type' => $data['product_type'], ]); // dump($data['articles']); // exit; diff --git a/app/Http/Controllers/Shop/HomeController.php b/app/Http/Controllers/Shop/HomeController.php index e0338063..16c5d44b 100644 --- a/app/Http/Controllers/Shop/HomeController.php +++ b/app/Http/Controllers/Shop/HomeController.php @@ -17,7 +17,7 @@ class HomeController extends Controller $data = self::init(); $data['display_by_rows'] = $input['by_rows'] ?? false; $data['shelves'] = Articles::getArticlesByHomepage(); - $data['text'] = Homepages::getLast(); + $data['text'] = Homepages::getHomepage(); // dump($data['shelves']); // exit; $data['tags'] = TagGroups::getWithTagsAndCountOffers(); diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index 397b3250..236de1ef 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -16,6 +16,9 @@ use Staudenmeir\EloquentHasManyDeep\HasRelationships; use App\Traits\Model\HasComments; use App\Traits\Model\Imageable; +use App\Models\Botanic\Variety; +use App\Models\Botanic\Specie; + class Article extends Model implements HasMedia { use Categorizable, EloquentJoin, HasComments, HasRelationships, Imageable, Powerjoins, Taggable, SoftDeletes, UserStamps; @@ -99,6 +102,11 @@ class Article extends Model implements HasMedia return $query->where($this->table . '.article_nature_id', $id); } + public function scopeByArticleNatures($query, $ids) + { + return $query->whereIn($this->table . '.article_nature_id', $ids); + } + public function scopeByCategories($query, $categories_id) { return $categories_id ? $query->whereHas('categories', function ($query) use ($categories_id) { @@ -121,6 +129,16 @@ class Article extends Model implements HasMedia }) : $query; } + public function scopeBotanic($query) + { + return $query->whereIn($this->table . '.product_type', [Variety::class, Specie::class]); + } + + public function scopeMerchandise($query) + { + return $query->byProduct(Merchandise::class); + } + public function scopeByProduct($query, $model) { return $query->where($this->table . '.product_type', $model); diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 7c5dc972..f1a8c250 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -219,12 +219,16 @@ class Articles $search = $options['search'] ?? false; $tags = $options['tags'] ?? false; $article_nature_id = $options['article_nature_id'] ?? false; + $article_nature_ids = $options['article_nature_ids'] ?? false; + $product_type = $options['product_type'] ?? false; $model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible(); $model = $category_id ? $model->byCategoryParent($category_id) : $model; $model = $tags ? $model->byTagsSelected($tags) : $model; $model = $search ? $model->search($search) : $model; $model = $article_nature_id ? $model->byArticleNature($article_nature_id) : $model; + $model = $article_nature_ids ? $model->byArticleNatures($article_nature_ids) : $model; + $model = ($product_type == 'botanic') ? $model->botanic() : $model->merchandise(); return $model; } @@ -453,19 +457,19 @@ class Articles switch ($article->product_type) { case 'App\Models\Botanic\Variety': $variety = $article->product; - $image = $variety->image; + $image = $variety->image ?? false; if (!$image) { $specie = $variety->specie; - $image = $specie->image; + $image = $specie->image ?? false; } break; case 'App\Models\Botanic\Specie': $specie = $article->product; - $image = $specie->image; + $image = $specie->image ?? false; break; case 'App\Models\Shop\Merchandise': $merchandise = $article->product; - $image = $merchandise->image; + $image = $merchandise->image ?? false; break; } } diff --git a/app/Repositories/Shop/Homepages.php b/app/Repositories/Shop/Homepages.php index e32d6541..f7bc4cc1 100644 --- a/app/Repositories/Shop/Homepages.php +++ b/app/Repositories/Shop/Homepages.php @@ -13,6 +13,11 @@ class Homepages return $model ? $model->text : ''; } + public static function getHomepage() + { + return self::get(1)->text; + } + public static function get($id) { return Homepage::find($id); diff --git a/resources/views/Shop/Articles/partials/article.blade.php b/resources/views/Shop/Articles/partials/article.blade.php index f06bd6be..a6f8774c 100644 --- a/resources/views/Shop/Articles/partials/article.blade.php +++ b/resources/views/Shop/Articles/partials/article.blade.php @@ -1,5 +1,5 @@ - -
+ +
{{ $product_name }}
@@ -11,29 +11,7 @@
{{ $article['product_name'] }}
- -
-
- - @if ($article['semences'] ?? false) - {{ $article['semences']['price'] ?? null }} € - @else - - - @endif -
- Semence -
-
- - @if ($article['plants'] ?? false) - {{ $article['plants']['price'] }} € - @else - - - @endif -
- Plant -
-
+ @include('Shop.Articles.partials.article_' . $product_type)
diff --git a/resources/views/Shop/Articles/partials/article_botanic.blade.php b/resources/views/Shop/Articles/partials/article_botanic.blade.php new file mode 100644 index 00000000..d54595a7 --- /dev/null +++ b/resources/views/Shop/Articles/partials/article_botanic.blade.php @@ -0,0 +1,22 @@ +
+
+ + @if ($article['semences'] ?? false) + {{ $article['semences']['price'] ?? null }} € + @else + - + @endif +
+ Semence +
+
+ + @if ($article['plants'] ?? false) + {{ $article['plants']['price'] }} € + @else + - + @endif +
+ Plant +
+
\ No newline at end of file diff --git a/resources/views/Shop/Articles/partials/article_merchandise.blade.php b/resources/views/Shop/Articles/partials/article_merchandise.blade.php new file mode 100644 index 00000000..78a02176 --- /dev/null +++ b/resources/views/Shop/Articles/partials/article_merchandise.blade.php @@ -0,0 +1,12 @@ +
+
+ + @if ($article['merchandises'] ?? false) + {{ $article['merchandises']['price'] ?? null }} € + @else + - + @endif +
+ Marchandise +
+
\ No newline at end of file diff --git a/resources/views/Shop/Articles/partials/article_rows.blade.php b/resources/views/Shop/Articles/partials/article_rows.blade.php index f0f45ccb..b8fb2193 100644 --- a/resources/views/Shop/Articles/partials/article_rows.blade.php +++ b/resources/views/Shop/Articles/partials/article_rows.blade.php @@ -1,5 +1,5 @@
-
+
-
+
-
- @if ($article['semences'] ?? false) -
- {{ $article['semences']['price'] ?? null }}
- {{ $article['semences']['variation'] }} -
- Quantité : 1 -
- @include('components.form.button', [ - 'class' => 'btn-green-dark basket semences mb-3 mt-2 shadow', - 'txt' => 'Ajouter au panier', - ]) -
- @endif -
-
- @if ($article['plants'] ?? false) -
- {{ $article['plants']['price'] ?? null }}
- {{ $article['plants']['variation'] }} -
- Quantité : 1 -
- @include('components.form.button', [ - 'class' => 'btn-success basket semences mb-3 mt-2 shadow', - 'txt' => 'Ajouter au panier', - ]) -
- @endif +
+ @include('Shop.Articles.partials.article_rows_' . $product_type)
diff --git a/resources/views/Shop/Articles/partials/article_rows_botanic.blade.php b/resources/views/Shop/Articles/partials/article_rows_botanic.blade.php new file mode 100644 index 00000000..8ff3b3aa --- /dev/null +++ b/resources/views/Shop/Articles/partials/article_rows_botanic.blade.php @@ -0,0 +1,26 @@ +@if ($article['semences'] ?? false) +
+ {{ $article['semences']['price'] ?? null }}
+ {{ $article['semences']['variation'] }} +
+ Quantité : 1 +
+ @include('components.form.button', [ + 'class' => 'btn-green-dark basket semences mb-3 mt-2 shadow', + 'txt' => 'Ajouter au panier', + ]) +
+@endif +@if ($article['plants'] ?? false) +
+ {{ $article['plants']['price'] ?? null }}
+ {{ $article['plants']['variation'] }} +
+ Quantité : 1 +
+ @include('components.form.button', [ + 'class' => 'btn-success basket semences mb-3 mt-2 shadow', + 'txt' => 'Ajouter au panier', + ]) +
+@endif \ No newline at end of file diff --git a/resources/views/Shop/Articles/partials/article_rows_merchandise.blade.php b/resources/views/Shop/Articles/partials/article_rows_merchandise.blade.php new file mode 100644 index 00000000..36aeabb5 --- /dev/null +++ b/resources/views/Shop/Articles/partials/article_rows_merchandise.blade.php @@ -0,0 +1,13 @@ +@if ($article['merchandises'] ?? false) +
+ {{ $article['merchandises']['price'] ?? null }}
+ {{ $article['merchandises']['variation'] }} +
+ Quantité : 1 +
+ @include('components.form.button', [ + 'class' => 'btn-success basket merchandises mb-3 mt-2 shadow', + 'txt' => 'Ajouter au panier', + ]) +
+@endif \ No newline at end of file diff --git a/resources/views/Shop/Shelves/partials/category_add.blade.php b/resources/views/Shop/Shelves/partials/category_add.blade.php index 40beed9a..a66afd27 100644 --- a/resources/views/Shop/Shelves/partials/category_add.blade.php +++ b/resources/views/Shop/Shelves/partials/category_add.blade.php @@ -6,8 +6,8 @@ @include('components.form.button', ['id' => 'by_rows', 'icon' => 'fa-list', 'class' => 'btn-secondary']) @endif - @include('components.form.button', ['id' => 'semences', 'icon' => 'fa-leaf', 'class' => 'bg-yellow yellow-dark']) - @include('components.form.button', ['id' => 'plants', 'icon' => 'fa-seedling', 'class' => 'bg-green text-white']) + @include('components.form.button', ['data_id' => 'botanic', 'icon' => 'fa-leaf', 'class' => 'products bg-yellow yellow-dark']) + @include('components.form.button', ['data_id' => 'merchandise', 'icon' => 'fa-seedling', 'class' => 'products bg-green text-white'])
@@ -15,12 +15,16 @@ @push('js') @endpush \ No newline at end of file diff --git a/resources/views/Shop/Shelves/shelve.blade.php b/resources/views/Shop/Shelves/shelve.blade.php index e7a2102b..fee9cdc1 100644 --- a/resources/views/Shop/Shelves/shelve.blade.php +++ b/resources/views/Shop/Shelves/shelve.blade.php @@ -3,31 +3,38 @@ ]) @section('content') -
-
- @include('Shop._partials.display_filters') -
-
-

- @foreach($breadcrumb ?? [] as $parent) - {{ $parent['name'] }} / - @endforeach - - {{ $category['name'] }} - -

-

{!! $category['description'] !!}

-
-
- @include('Shop.Shelves.partials.category_add') -
-
- @include('Shop.Tags.partials.filter') - - @if ($display_by_rows ?? false) - @include('Shop.Shelves.partials.category_articles_rows') - @else - @include('Shop.Shelves.partials.category_articles') - @endif + {{ Form::open(['id' => 'category-form', 'autocomplete' => 'off']) }} + + + +
+
+ @include('Shop._partials.display_filters') +
+
+

+ @foreach($breadcrumb ?? [] as $parent) + {{ $parent['name'] }} / + @endforeach + + {{ $category['name'] }} + +

+

{!! $category['description'] !!}

+
+
+ @include('Shop.Shelves.partials.category_add') +
+
+ + @include('Shop.Tags.partials.filter') + + @if ($display_by_rows ?? false) + @include('Shop.Shelves.partials.category_articles_rows') + @else + @include('Shop.Shelves.partials.category_articles') + @endif + + @endsection