diff --git a/app/Http/Controllers/Shop/BasketController.php b/app/Http/Controllers/Shop/BasketController.php index 83f317fa..b92ac1c1 100644 --- a/app/Http/Controllers/Shop/BasketController.php +++ b/app/Http/Controllers/Shop/BasketController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Shop; use App\Http\Controllers\Controller; use App\Repositories\Core\User\ShopCart; use App\Repositories\Shop\Baskets; +use App\Repositories\Shop\Deliveries; use App\Repositories\Shop\DeliveryTypes; use App\Repositories\Shop\Offers; use App\Repositories\Shop\Orders; @@ -63,15 +64,9 @@ class BasketController extends Controller return ShopCart::count(); } - public function getBasketTotal($deliveryTypeId = false) + public function getBasketTotal($deliveryId = false, $deliveryTypeId = false) { - $data = [ - 'basket' => ShopCart::getSummary(), - ]; - - $weight = Baskets::getWeight(); - - $data['basket']['shipping'] = DeliveryTypes::getPrice($deliveryTypeId, $weight); + $data['basket'] = Baskets::getBasketTotal($deliveryId, $deliveryTypeId); return view('Shop.Baskets.partials.basketTotal', $data); } diff --git a/app/Http/Controllers/Shop/OrderController.php b/app/Http/Controllers/Shop/OrderController.php index 4610aebb..441bd8aa 100644 --- a/app/Http/Controllers/Shop/OrderController.php +++ b/app/Http/Controllers/Shop/OrderController.php @@ -40,15 +40,18 @@ class OrderController extends Controller { if (ShopCart::count()) { $customer = Customers::getWithAddresses(); - + $data = [ 'customer' => $customer ? $customer->toArray() : false, - 'basket' => ShopCart::getSummary(), + 'basket' => Baskets::getBasketTotal(), 'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(), 'sale_channel' => SaleChannels::getDefault()->toArray(), - 'delivery_types' => DeliveryTypes::getAll(), + 'delivery_types' => DeliveryTypes::getWithPrice(Baskets::getWeight()), ]; + // dump($data); + // exit; + return view('Shop.Orders.order', $data); } else { return redirect()->route('home'); diff --git a/app/Repositories/Shop/Baskets.php b/app/Repositories/Shop/Baskets.php index c6aa3d44..c9c2f8fe 100644 --- a/app/Repositories/Shop/Baskets.php +++ b/app/Repositories/Shop/Baskets.php @@ -2,7 +2,6 @@ namespace App\Repositories\Shop; -use App\Models\Shop\Offer; use App\Repositories\Core\User\ShopCart; class Baskets @@ -17,13 +16,21 @@ class Baskets return $data ? ShopCart::add($data, $update) : false; } + public static function getBasketTotal($deliveryId = false, $deliveryTypeId = false) + { + $saleChannelId = $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID(); + + return self::getBasketSummary($saleChannelId, $deliveryTypeId); + } + public static function getBasketSummary($saleChannelId = false, $deliveryTypeId = false) { - $basket = ShopCart::getContent(); - $offers = Offer::with('variation')->whereIn('id', ShopCart::keys())->get(); $total = 0; $totalTaxed = 0; $totalWeight = 0; + $basket = ShopCart::getContent(); + $offers = Offers::getWithVariationByIds(self::getIds()); + foreach ($basket as $item) { $offer = $offers->where('id', $item->id)->first(); $prices = Offers::getPrice($item->id, $item->quantity, $saleChannelId); @@ -33,15 +40,18 @@ class Baskets $totalTaxed += self::getTotal($item->quantity, $prices->price_taxed); $totalWeight += $weight; } - $shipping = 0; + $shipping = DeliveryTypeCalculations::getPriceByDeliveryType($deliveryTypeId, $totalWeight); + $data = [ 'detail' => $detail, 'total' => $total, 'taxes' => $totalTaxed - $total, 'total_taxed' => $totalTaxed, - 'total_weight' => $totalWeight, 'shipping' => $shipping, 'total_shipped' => $totalTaxed + $shipping, + 'count' => ShopCart::count(), + 'quantity' => ShopCart::getTotalQuantity(), + 'weight' => $totalWeight, ]; return $data ?? false; @@ -66,7 +76,7 @@ class Baskets public static function getWeight() { $basket = ShopCart::getContent(); - $offers = Offer::with('variation')->byIds(ShopCart::keys())->get(); + $offers = Offers::getWithVariationByIds(ShopCart::keys()); $totalWeight = 0; foreach ($basket as $item) { $offer = $offers->where('id', $item->id)->first(); @@ -86,15 +96,7 @@ class Baskets { $saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID(); $basket = ShopCart::getContent(); - // dump($basket->toArray()); - $offers = Offer::with([ - 'variation', - 'article.article_nature', - 'article.product.Specie', - 'article.image', - 'price_lists.price_list_values', - ])->withPriceListsBySaleChannel($saleChannelId) - ->whereIn('id', ShopCart::keys())->get(); + $offers = Offers::getWithPricesByIds(self::getIds(), $saleChannelId); foreach ($basket as $item) { $offer = $offers->where('id', $item->id)->first(); $article_nature = strtolower($offer->article->article_nature->name); @@ -130,4 +132,9 @@ class Baskets return $offer->article->name; // return $offer->article->name . ' (' . $offer->variation->name . ')'; } + + public static function getIds() + { + return ShopCart::keys(); + } } diff --git a/app/Repositories/Shop/DeliveryTypes.php b/app/Repositories/Shop/DeliveryTypes.php index dd873d7b..e2fad483 100644 --- a/app/Repositories/Shop/DeliveryTypes.php +++ b/app/Repositories/Shop/DeliveryTypes.php @@ -9,6 +9,21 @@ class DeliveryTypes { use Basic; + public static function getWithPrice($weight) + { + $data = []; + $types = self::getAll(); + + foreach ($types as $type) { + $data[$type->id] = [ + 'name' => $type->name, + 'price' => self::getPrice($type->id, $weight), + ]; + } + + return $data; + } + public static function getPrice($id, $weight) { return DeliveryTypeCalculations::getPriceByDeliveryType($id, $weight); diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index 5968d3db..12aa4f44 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -25,6 +25,23 @@ class Offers return $offer ? $offer->weight * $quantity : 0; } + public static function getWithVariationByIds($ids) + { + return Offer::with('variation')->byIds($ids)->get(); + } + public static function getWithPricesByIds($ids, $saleChannelId = false) + { + $saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID(); + + return Offer::with([ + 'variation', + 'article.article_nature', + 'article.product.Specie', + 'article.image', + 'price_lists.price_list_values', + ])->withPriceListsBySaleChannel($saleChannelId)->byIds($ids)->get(); + } + public static function getFull($id, $saleChannelId = false) { $saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID(); diff --git a/app/Traits/Model/Basic.php b/app/Traits/Model/Basic.php index a5acda32..bebcf580 100644 --- a/app/Traits/Model/Basic.php +++ b/app/Traits/Model/Basic.php @@ -149,6 +149,11 @@ trait Basic return self::getModelRelations($relations, $relationsCount)->withTrashed()->find($id); } + public static function getAllArray($relations = false, $relationsCount = false) + { + return self::getAll($relations, $relationsCount)->toArray(); + } + public static function getAll($relations = false, $relationsCount = false) { return self::getModelRelations($relations, $relationsCount)->get(); diff --git a/resources/views/Shop/Baskets/partials/basketTotal.blade.php b/resources/views/Shop/Baskets/partials/basketTotal.blade.php index b88d3036..ee64248f 100644 --- a/resources/views/Shop/Baskets/partials/basketTotal.blade.php +++ b/resources/views/Shop/Baskets/partials/basketTotal.blade.php @@ -13,27 +13,32 @@ {{ $basket['quantity'] ?? 0 }} ARTICLES
- {{ $basket['total'] ?? 0 }} € + + {{ $basket['total_taxed'] ?? 0 }} +
- +
+@endif +
TOTAL TTC
- {{ App\Repositories\Core\User\ShopCart::fixDecimal($basket['total'] ?? 0) }} - € + + {{ $basket['total_shipped'] ?? 0 }} +
diff --git a/resources/views/Shop/Orders/order.blade.php b/resources/views/Shop/Orders/order.blade.php index 66d4fa48..363c29b0 100644 --- a/resources/views/Shop/Orders/order.blade.php +++ b/resources/views/Shop/Orders/order.blade.php @@ -29,7 +29,7 @@ @if ($basket['count'])
- @include('Shop.Baskets.partials.basketTotal') + @include('Shop.Baskets.partials.basketTotal', ['basket' => $basket])
@endif diff --git a/resources/views/Shop/Orders/partials/shipping.blade.php b/resources/views/Shop/Orders/partials/shipping.blade.php index 859f97ab..6cf234e5 100644 --- a/resources/views/Shop/Orders/partials/shipping.blade.php +++ b/resources/views/Shop/Orders/partials/shipping.blade.php @@ -1,3 +1,28 @@ -@foreach ($delivery_types as $delivery_type) - -@endforeach +@if ($delivery_types ?? false) + + + + + + + @foreach ($delivery_types as $delivery_type_id => $delivery_type) + + + + + + @endforeach +
+ Choix du transporteur +
+ @include('components.form.radios.icheck', [ + 'name' => 'delivery_type_id', + 'val' => $delivery_type_id, + 'check' => false, + ]) + + {{ $delivery_type['name'] }} + + {{ $delivery_type['price'] }} € +
+@endif diff --git a/routes/Shop/Baskets.php b/routes/Shop/Baskets.php index dfa5ce5d..18977fff 100644 --- a/routes/Shop/Baskets.php +++ b/routes/Shop/Baskets.php @@ -5,7 +5,7 @@ Route::prefix('Panier')->name('Basket.')->group(function () { Route::post('addBasket', 'BasketController@addBasket')->name('addBasket'); Route::get('modalBasket/{offer_id?}/{quantity?}', 'BasketController@modalBasket')->name('modalBasket'); Route::get('getBasket', 'BasketController@getBasket')->name('getBasket'); - Route::get('getBasketTotal', 'BasketController@getBasketTotal')->name('getBasketTotal'); + Route::get('getBasketTotal/{deliveryId?}/{deliveryTypeId?}', 'BasketController@getBasketTotal')->name('getBasketTotal'); Route::get('getSummary', 'BasketController@getSummary')->name('getSummary'); Route::get('countBasket', 'BasketController@countBasket')->name('countBasket'); Route::get('clearBasket', 'BasketController@clearBasket')->name('clearBasket');