From 3641bd7d68de72c27689b61539ddf13183ab7852 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Tue, 18 Jan 2022 00:08:04 +0100 Subject: [PATCH] Fix on data for article, problem with id on polymorphic --- app/Http/Controllers/Shop/HomeController.php | 6 ++-- app/Repositories/Shop/Articles.php | 33 ++++++++++++++++--- .../2022_01_07_233439_create_stats_tables.php | 21 ++++++++++++ .../Shop/Articles/partials/article.blade.php | 17 +++++----- .../partials/category_articles.blade.php | 2 +- 5 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 database/migrations/2022_01_07_233439_create_stats_tables.php diff --git a/app/Http/Controllers/Shop/HomeController.php b/app/Http/Controllers/Shop/HomeController.php index 1ef9d994..fc3d82da 100644 --- a/app/Http/Controllers/Shop/HomeController.php +++ b/app/Http/Controllers/Shop/HomeController.php @@ -20,10 +20,10 @@ class HomeController extends Controller { $data = self::init(); // $data['offers'] = Offers::getLast()->toArray(); - $data['articles'] = Articles::getArticlesWithOffers()->toArray(); + $data['articles'] = Articles::getArticlesToSell(); // $data['prices'] = $data['articles']['offers'][0]['tariff']['price_lists'][0]['price_list_values'][0]; - dump($data); - exit; + // dump($data); + // exit; return view('Shop.home', $data); } } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 4622f856..620dbc5c 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -62,17 +62,42 @@ class Articles public static function getArticlesToSell() { $articles = self::getArticlesWithOffers(); + // dump($articles->toArray()); foreach ($articles as $article) { - $data[$article->article_nature->name][$article->name][] = [ - 'description' => $article->description, - ]; + $price_lists = $article->offers[0]->tariff->price_lists->toArray(); + // dump($price_lists); + if (count($price_lists)) { + $data[$article->name] = [ + 'description' => (!empty($article->description)) ? $article->description : $article->product->description, + 'image' => $article->image, + 'product_type' => $article->product_type, + 'product_id' => $article->product_id, + ]; + $prices = $price_lists[0]['price_list_values'][0]; + $article_nature_name = strtolower($article->article_nature->name); + // dump($prices); + $data[$article->name][$article_nature_name] = [ + 'article_id' => $article->id, + 'offer_id' => $article->offers[0]->id, + 'quantity' => $prices['quantity'], + 'price' => $prices['price_taxed'], + ]; + } } + // dump($data); + // exit; return $data; } public static function getArticlesWithOffers() { - return Article::visible()->withAvailableOffers()->with(['image', 'article_nature', 'offers.tariff.price_lists.price_list_values'])->get(); + return Article::visible()->withAvailableOffers()->with([ + 'image', + 'product', + 'article_nature', + 'offers.variation', + 'offers.tariff.price_lists.price_list_values', + ])->get(); } public static function getFull($id) diff --git a/database/migrations/2022_01_07_233439_create_stats_tables.php b/database/migrations/2022_01_07_233439_create_stats_tables.php new file mode 100644 index 00000000..98ed4541 --- /dev/null +++ b/database/migrations/2022_01_07_233439_create_stats_tables.php @@ -0,0 +1,21 @@ +id(); + + $table->string('name'); + $table->string('type'); + $table->bigInteger('value'); + + $table->timestamps(); + }); + } +} diff --git a/resources/views/Shop/Articles/partials/article.blade.php b/resources/views/Shop/Articles/partials/article.blade.php index 2e63666c..35909ec6 100644 --- a/resources/views/Shop/Articles/partials/article.blade.php +++ b/resources/views/Shop/Articles/partials/article.blade.php @@ -1,8 +1,8 @@ - +
...
- {{ $article['name'] }} + {{ $product_name }} @@ -10,14 +10,15 @@

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

diff --git a/resources/views/Shop/layout/partials/category_articles.blade.php b/resources/views/Shop/layout/partials/category_articles.blade.php index 756fcce1..3d8a5f90 100644 --- a/resources/views/Shop/layout/partials/category_articles.blade.php +++ b/resources/views/Shop/layout/partials/category_articles.blade.php @@ -1,5 +1,5 @@
- @foreach ($articles as $article) + @foreach ($articles as $product_name => $article)
@include('Shop.Articles.partials.article')