84 lines
2.2 KiB
PHP
84 lines
2.2 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
|
|
{
|
|
/**
|
|
* @deprecated
|
|
*/
|
|
// public function index(Request $request)
|
|
// {
|
|
// return view('basket');
|
|
// }
|
|
|
|
/**
|
|
* ajout de produit au panier
|
|
*/
|
|
public function addToCart(Request $request)
|
|
{
|
|
$product = Product::find($request->id);
|
|
Cart::add($product, $request->qty);
|
|
|
|
return $this->getCart();
|
|
}
|
|
|
|
/**
|
|
* suppression de produit du panier
|
|
*/
|
|
public function removeFromCart(Request $request)
|
|
{
|
|
$rowId = $request->rowId;
|
|
Cart::remove($rowId);
|
|
return $this->getCart();
|
|
}
|
|
|
|
/**
|
|
* vidage de panier
|
|
*/
|
|
public function emptyCart() {
|
|
Cart::destroy();
|
|
return $this->getCart();
|
|
}
|
|
|
|
/**
|
|
* récupération du panier
|
|
*/
|
|
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;
|
|
}
|
|
}
|