How do I make a "Clear Cart" button in the shopping card section?
Not: Version 4.20
foreach (var item in _workContext.CurrentCustomer.ShoppingCartItems)
_shoppingCartService.DeleteShoppingCartItem(item.Id);
foreach (var item in _workContext.CurrentCustomer.ShoppingCartItems)
_shoppingCartService.DeleteShoppingCartItem(item.Id);
public virtual IActionResult ClearShoppingCart()
{
if(!_permissionService.Authorize(StandardPermissionProvider.ManageCurrentCarts))
return AccessDeniedDataTablesJson();
foreach (var item in _workContext.CurrentCustomer.ShoppingCartItems)
_shoppingCartService.DeleteShoppingCartItem(item.Id);
return RedirectToRoute("ShoppingCart");
}
public virtual IActionResult ClearShoppingCart()
{
if(!_permissionService.Authorize(StandardPermissionProvider.ManageCurrentCarts))
return AccessDeniedDataTablesJson();
foreach (var item in _workContext.CurrentCustomer.ShoppingCartItems)
_shoppingCartService.DeleteShoppingCartItem(item.Id);
return RedirectToRoute("ShoppingCart");
}
[HttpPost, ActionName("Cart")]
[FormValueRequired("ClearShoppingCart")]
[HttpPost, ActionName("Cart")]
[FormValueRequired("ClearShoppingCart")]
public virtual IActionResult ClearShoppingCart()
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrentCarts))
return AccessDeniedDataTablesJson();
var shoppingCartItem = _workContext.CurrentCustomer.ShoppingCartItems.ToList();
foreach (var item in shoppingCartItem)
_shoppingCartService.DeleteShoppingCartItem(item.Id);
return RedirectToRoute("ShoppingCart");
}
[HttpPost, ActionName("Cart")]
[FormValueRequired("ClearShoppingCart")]
[HttpPost, ActionName("Cart")]
[FormValueRequired("ClearShoppingCart")]
public virtual IActionResult ClearShoppingCart()
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrentCarts))
return AccessDeniedDataTablesJson();
var shoppingCartItem = _workContext.CurrentCustomer.ShoppingCartItems.ToList();
foreach (var item in shoppingCartItem)
_shoppingCartService.DeleteShoppingCartItem(item.Id);
return RedirectToRoute("ShoppingCart");
}