<?php
namespace App\Controller;
use App\Entity\Produit;
use App\Service\CartService;
use App\Repository\MenuRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class CartController extends AbstractController
{
#[Route('/mon-panier', name: 'cart_index')]
public function index(CartService $cartService, MenuRepository $menuRepository): Response
{
return $this->render('cart/index.html.twig',[
'menus'=>$menuRepository->findAll(),
'cart'=>$cartService->getTotal()
]);
}
#[Route('/mon-panier/add/{id}', name: 'cart_add')]
public function addToCart(CartService $cartService,Produit $produit): Response
{
$cartService->addToCart($produit->getId());
return $this->redirectToRoute('cart_index');
}
#[Route('/mon-panier/decrease/{id}', name: 'cart_decrease')]
public function decrease(CartService $cartService, Produit $produit): RedirectResponse
{
$cartService->decrease($produit->getId());
return $this->redirectToRoute('cart_index');
}
#[Route('/mon-panier/remove/{id}', name: 'cart_remove')]
public function removeToCart(CartService $cartService, Produit $produit): Response
{
$cartService->removeToCart($produit->getId());
return $this->redirectToRoute('cart_index');
}
#[Route('/mon-panier/removeAll', name: 'cart_removeAll')]
public function removeAll(CartService $cartService): Response
{
$cartService->removeCartAll();
return $this->redirectToRoute('app_sousmenu_decouvertees');
}
}