ldc-boutique-cnc/app/Http/Controllers/BasketController.php
Olivier Legat bce4c2f88c Offres Spéciales :
commit 2bdbfaec541c3d51489f32e0fa6f7523ca4e4f6f
Author: Olivier Legat <olivier.legat@ldc.fr>
Date:   Thu Apr 8 15:48:13 2021 +0200

    arrondis de taxe dans le panier

commit ce748bcac15a0b633cacc06b8232cbb92a8e455c
Author: Olivier Legat <olivier.legat@ldc.fr>
Date:   Thu Apr 8 11:53:54 2021 +0200

    Prix calcules - affichés

commit cc79e7c633d81290371eceabe9864d4d0ee9e4a5
Author: Olivier Legat <olivier.legat@ldc.fr>
Date:   Wed Apr 7 18:09:12 2021 +0200

    Affichage des promowork in progress => prix remisés

commit 8545d1079da2456f090557eeef005e4d37154a1e
Author: Olivier Legat <olivier.legat@ldc.fr>
Date:   Wed Apr 7 13:04:28 2021 +0200

    resource BO Promotions

commit d7145835de675da32e57bec3f0b8f06e1e447b27
Author: Olivier Legat <olivier.legat@ldc.fr>
Date:   Tue Apr 6 18:23:36 2021 +0200

    structure DB, debut BO
2021-04-08 15:49:20 +02:00

69 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Gloudemans\Shoppingcart\Facades\Cart;
class BasketController extends Controller
{
public function index(Request $request)
{
return view('basket');
}
public function addToCart(Request $request)
{
$product = Product::find($request->id);
Cart::add($product, $request->qty);
return $this->getCart();
}
public function removeFromCart(Request $request)
{
$rowId = $request->rowId;
Cart::remove($rowId);
return $this->getCart();
}
public function emptyCart() {
Cart::destroy();
return $this->getCart();
}
public function getCart() {
$dbpanier = new Collection();
foreach (Cart::content() as $row) {
$product = $row->model;
//$product->additionnalProductInfo = $product->additionnalProductInfo($product->product_type);
$product->calculatedPrices = $product->getCalcPrices();
$row->setTaxRate($product->tax->rate);
$row->setDiscountRate($product->discountRate);
$cartextendedItem = array(
'cartItem' => $row,
'product' => $product
);
$dbpanier->add($cartextendedItem);
}
$cartInfos = array(
"totalTTC" => Cart::total(),
'totalTVA' => Cart::tax(), //total des taxes
'totalHT' => Cart::subtotal(), //total sans les taxes
'totalweight' => Cart::weight(), //poids total des items
'totalHTbefore' => Cart::priceTotal(), //total avant taxes et remises
'totaldiscount' => Cart::discount(), //total des remises
'countItems' => Cart::count(), //nb de produits dans le cart
);
$cartReturn = array($dbpanier,$cartInfos);
return $cartReturn;
}
}