Skip to content
Snippets Groups Projects
Commit 75aa96e3 authored by Axel Po's avatar Axel Po
Browse files

feat: add delete cart btn

parent 75009211
Branches
2 merge requests!6Dev,!4Feat/cart
......@@ -19,7 +19,7 @@ class CartController extends AbstractController
public function index(CartRepository $cartRepository): Response
{
$user = $this->getUser(); // Get the current user object
$carts = $cartRepository->findBy(['user_id' => $user]); // Get the carts for the current user
$carts = $cartRepository->findBy(['user_id' => $user], ['id' => 'DESC']);
return $this->render('cart/index.html.twig', [
'carts' => $carts,
......@@ -77,7 +77,7 @@ class CartController extends AbstractController
]);
}
#[Route('/{id}', name: 'app_cart_delete', methods: ['POST'])]
#[Route('/{id}', name: 'app_cart_delete', methods: ['POST', 'DELETE'])]
public function delete(Request $request, Cart $cart, CartRepository $cartRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$cart->getId(), $request->request->get('_token'))) {
......
......@@ -2,29 +2,60 @@
body %}
<section>
<h3 class="font-bold text-5xl">Votre panier</h3>
{% if app.user %}
<p class="mt-2">Connecté sous {{ app.user.email }}</p>
{% endif %}
<div class="flex flex-col my-12">
{% for cart in carts %}
<article class="border-t border-b py-4">
<div class="flex items-center justify-between">
<div class="flex items-center gap-6">
{% for product in cart.getProductId() %}
<img class="w-[60px]" src="{{ asset(product.imageSrc) }}" alt="" />
{% for product in cart.getProductId() %}
<img class="w-[80px]" src="{{ asset(product.imageSrc) }}" alt="" />
<div>
<h4 class="text-lg">{{ product.getTitle() }}</h4>
<p class="text-sm font-light truncate text-ellipsis max-w-[30vw]">
<div class="flex gap-4 items-center">
<h4 class="text-lg">{{ product.getTitle() }}</h4>
<span class="text-orange-500 font-sm font-bold"
>x {{ cart.getQuantity() }}</span
>
</div>
<p
class="text-sm font-light truncate text-ellipsis mt-2 max-w-[30vw]"
>
{{ product.Description() }}
</p>
{% endfor %}
</div>
</div>
<div>
<span class="font-bold text-orange-500 text-lg">{{ cart.getProductId().first().getPrice() }}</span>
<span class="font-bold text-orange-500 text-lg"
>{{ cart.getProductId().first().getPrice() }}</span
>
</div>
</div>
<div class="flex gap-6 mt-6">
<a class="hover:text-orange-400 transition-colors" href="#">Voir</a>
<a class="text-red-500" href="#">Supprimer</a>
<a
class="hover:text-orange-400 transition-colors"
href="{{
path('app_product_show', {
id: cart.getProductId().first().getId()
})
}}"
>Voir</a
>
<form
action="{{ path('app_cart_delete', { id: cart.getId() }) }}"
method="POST"
>
<input type="hidden" name="_method" value="DELETE" />
<input
type="hidden"
name="_token"
value="{{ csrf_token('delete' ~ cart.getId()) }}"
/>
<button type="submit" class="text-red-500">Supprimer</button>
</form>
</div>
</article>
{% else %}
......@@ -32,11 +63,13 @@ body %}
{% endfor %}
</div>
<a href="#">Retour aux achats</a>
<a
href="{{ path('home') }}"
class="inline-block bg-orangeLight py-4 px-12 rounded-md"
>Retour</a
>
</section>
{% endblock %}
{# {% extends 'base.html.twig' %} {% block title %}Cart index{%
{% endblock %} {# {% extends 'base.html.twig' %} {% block title %}Cart index{%
endblock %} {% block body %}
<h1>Cart index</h1>
......
......@@ -16,14 +16,14 @@
{{ product.description }}
</p>
<form action="{{ path('app_cart_new') }}" method="post">
<input type="hidden" name="produit_id" value="{{ product.id }}" />
<button type="submit">Ajouter au panier</button>
</form>
{# <a class="inline-block bg-orangeLight py-4 px-12 rounded-md" href="cart.html"
>Ajouter au pannier</a
> #}
{% if app.user %}
<form action="{{ path('app_cart_new') }}" method="post">
<input type="hidden" name="produit_id" value="{{ product.id }}" />
<button class="inline-block bg-orangeLight py-4 px-12 rounded-md" type="submit">Ajouter au panier</button>
</form>
{% else %}
<a class="inline-block bg-orangeLight py-4 px-12 rounded-md" href="{{ path('app_login') }}">Connectez-vous pour ajouter au panier</a>
{% endif %}
</div>
</section>
{% endblock %} {#
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment