From 6e3866b34260be5843e8b0f8fc6525fd02d9c217 Mon Sep 17 00:00:00 2001 From: Eric WAGNER <eric.wagner@etu.unistra.fr> Date: Thu, 30 Mar 2023 16:27:53 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20de=20la=20m=C3=A9thode=20delete=20du=20?= =?UTF-8?q?panier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/CartController.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Controller/CartController.php b/src/Controller/CartController.php index 7c40414..92f94fd 100644 --- a/src/Controller/CartController.php +++ b/src/Controller/CartController.php @@ -85,4 +85,23 @@ class CartController extends AbstractController return $this->redirectToRoute("app_cart_index"); } + + #[Route('/delete/{id}', name: 'app_cart_delete', methods: ['GET', 'POST'])] + public function delete(Clothes $clothes, SessionInterface $session) + { + // On récupère le panier actuel + $panier = $session->get("panier", []); + $id = $clothes->getId(); + + if (!empty($panier[$id])) { + if ($panier[$id] > 1) { + unset($panier[$id]); + } + } + + // On sauvegarde dans la session + $session->set("panier", $panier); + + return $this->redirectToRoute("app_cart_index"); + } } -- GitLab