src/Controller/CartController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Produit;
  4. use App\Service\CartService;
  5. use App\Repository\MenuRepository;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. class CartController extends AbstractController
  11. {
  12.     #[Route('/mon-panier'name'cart_index')]
  13.     public function index(CartService $cartServiceMenuRepository $menuRepository): Response
  14.     {
  15.         return $this->render('cart/index.html.twig',[
  16.             'menus'=>$menuRepository->findAll(),
  17.             'cart'=>$cartService->getTotal()
  18.         ]);
  19.     }
  20.     #[Route('/mon-panier/add/{id}'name'cart_add')]
  21.     public function addToCart(CartService $cartService,Produit $produit): Response
  22.     {
  23.         $cartService->addToCart($produit->getId());
  24.         return $this->redirectToRoute('cart_index');
  25.     }
  26.     #[Route('/mon-panier/decrease/{id}'name'cart_decrease')]
  27.     public function decrease(CartService $cartServiceProduit $produit): RedirectResponse
  28.     {
  29.         $cartService->decrease($produit->getId());
  30.         return $this->redirectToRoute('cart_index');
  31.     }
  32.     #[Route('/mon-panier/remove/{id}'name'cart_remove')]
  33.     public function removeToCart(CartService $cartServiceProduit $produit): Response
  34.     {
  35.         $cartService->removeToCart($produit->getId());
  36.         return $this->redirectToRoute('cart_index');
  37.     }
  38.     #[Route('/mon-panier/removeAll'name'cart_removeAll')]
  39.     public function removeAll(CartService $cartService): Response
  40.     {
  41.         $cartService->removeCartAll();
  42.         return $this->redirectToRoute('app_sousmenu_decouvertees');
  43.     }
  44. }