From 6fc6451f6f2a6901a8943f37a140b2ea371e18af Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Sun, 24 Apr 2022 23:20:52 +0200 Subject: [PATCH] Add new data in getBasket context --- .../Controllers/Shop/BasketController.php | 8 ++--- app/Models/Shop/Offer.php | 33 ++++++++++++------- app/Repositories/Shop/Offers.php | 10 ++++-- resources/views/Shop/Baskets/basket.blade.php | 9 ++--- .../Shop/Baskets/partials/article.blade.php | 3 +- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/Shop/BasketController.php b/app/Http/Controllers/Shop/BasketController.php index f2276eb8..8a579d0a 100644 --- a/app/Http/Controllers/Shop/BasketController.php +++ b/app/Http/Controllers/Shop/BasketController.php @@ -12,11 +12,10 @@ use App\Repositories\Shop\Orders; class BasketController extends Controller { - public function getPrice(Request $request) { $offer_id = $request->input('offer_id'); - $quantity = $request->input('quantity'); + $quantity = $request->input('quantity') ?? 1; $price = Offers::getPrice($offer_id, $quantity)->price_taxed; return number_format($quantity * $price, 2); } @@ -24,12 +23,11 @@ class BasketController extends Controller public function addBasket(Request $request) { $offer_id = $request->input('offer_id'); - $quantity = $request->input('quantity'); + $quantity = $request->input('quantity') ?? 1; $update = $request->input('update') ?? false; return Offers::addBasket($offer_id, $quantity, $update); } - public function modalBasket($offer_id, $quantity) { $data['offer'] = Offers::getFull($offer_id)->toArray(); @@ -41,6 +39,8 @@ class BasketController extends Controller { $data = self::init(); $data['basket'] = Offers::getBasket(); + dump($data['basket']); + exit; return view('Shop.Baskets.basket', $data); } diff --git a/app/Models/Shop/Offer.php b/app/Models/Shop/Offer.php index d7e5afb9..8846ca59 100644 --- a/app/Models/Shop/Offer.php +++ b/app/Models/Shop/Offer.php @@ -6,10 +6,11 @@ use Illuminate\Database\Eloquent\Model; use Znck\Eloquent\Traits\BelongsToThrough; use App\Traits\Model\HasComments; +use Staudenmeir\EloquentHasManyDeep\HasRelationships; class Offer extends Model { - use BelongsToThrough, HasComments; + use BelongsToThrough, HasComments, HasRelationships; protected $guarded = ['id']; protected $table = 'shop_offers'; @@ -27,6 +28,26 @@ class Offer extends Model ]); } + public function categories() + { + return $this->article->categories(); + } + + public function price_lists() + { + return $this->hasManyThrough(PriceList::class, Tariff::class, 'id', 'tariff_id', 'tariff_id', 'id'); + } + + public function price_list_values() + { + return $this->hasManyDeep( + PriceListValue::class, + [Tariff::class, PriceList::class], + ['id', 'tariff_id', 'price_list_id'], + ['tariff_id', 'id', 'id'], + ); + } + public function tariff() { return $this->belongsTo(Tariff::class); @@ -37,16 +58,6 @@ class Offer extends Model return $this->belongsTo(Variation::class); } - public function price_lists() - { - return $this->hasManyThrough(PriceList::class, Tariff::class, 'id', 'tariff_id', 'tariff_id', 'id'); - } - - public function categories() - { - return $this->article->categories(); - } - public function tags() { return $this->article->tags(); diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index 980b681a..00c13e5f 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -47,10 +47,16 @@ class Offers { $basket = ShopCart::getContent(); // dump($basket->toArray()); - $offers = Offer::with(['variation', 'article.article_nature', 'article.image'])->whereIn('id', ShopCart::keys())->get(); - + $offers = Offer::with([ + 'variation', + 'article.article_nature', + 'article.product.Specie', + 'article.image', + ])->whereIn('id', ShopCart::keys())->get(); foreach ($basket as $item) { $offer = $offers->where('id', $item->id)->first(); + dump($offer->toArray()); + exit; $article_nature = strtolower($offer->article->article_nature->name); $data[$article_nature][] = [ 'id' => (int) $item->id, diff --git a/resources/views/Shop/Baskets/basket.blade.php b/resources/views/Shop/Baskets/basket.blade.php index a745341b..3e246f1e 100644 --- a/resources/views/Shop/Baskets/basket.blade.php +++ b/resources/views/Shop/Baskets/basket.blade.php @@ -19,7 +19,7 @@ @foreach ($basket as $nature => $items)
-

{{ ucfirst($nature) }}

+

{{ $nature }}

@foreach ($items as $item) @include('Shop.Baskets.partials.article') @endforeach @@ -32,6 +32,7 @@
Tarif appliqué +
{{ $sale_channel['name'] ?? '' }} @@ -41,7 +42,7 @@
ARTICLES
-
+
@@ -49,12 +50,12 @@
LIVRAISON
-
+
5

-
+
TOTAL TTC
diff --git a/resources/views/Shop/Baskets/partials/article.blade.php b/resources/views/Shop/Baskets/partials/article.blade.php index 5886a062..eaac5da1 100644 --- a/resources/views/Shop/Baskets/partials/article.blade.php +++ b/resources/views/Shop/Baskets/partials/article.blade.php @@ -1,9 +1,10 @@
- +

{{ $item['name'] }}

+

{{ $item['article']['product']['specie']['latin'] }}

{{ $item['variation'] }}