Skip to content

Commit

Permalink
Improve: change delete cart item to POST
Browse files Browse the repository at this point in the history
  • Loading branch information
robertSt7 authored and dvesh3 committed Oct 10, 2023
1 parent 3cb015e commit 59309c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Controller/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,14 @@ public function cartListingAction(Request $request, BreadcrumbHelperService $bre
}

/**
* @Route("/cart/remove-from-cart", name="shop-remove-from-cart")
* @Route("/cart/remove-from-cart", name="shop-remove-from-cart", methods={"POST"})
*/
public function removeFromCartAction(Request $request, Factory $ecommerceFactory): RedirectResponse
{
if (!$this->isCsrfTokenValid('cartListing', $request->request->get('_csrf_token'))) {
throw new \Exception('Invalid request');
}

$id = $request->query->getInt('id');
$product = AbstractProduct::getById($id);

Expand Down
4 changes: 2 additions & 2 deletions templates/cart/cart_listing.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@
</div>
</div>
<div class="col-2 col-sm-2 col-md-1 text-right px-md-0">
<a href="{{ path('shop-remove-from-cart', {id: item.itemKey}) }}" class="btn btn-outline-danger btn-sm">
<button type="submit" class="btn btn-outline-danger btn-sm" formaction="{{ path('shop-remove-from-cart', {id: item.itemKey}) }}">
<i class="fa fa-trash" aria-hidden="true"></i>
</a>
</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 59309c1

Please sign in to comment.