From 2bce25249d8cd5dca1753f409de9d02af240216a Mon Sep 17 00:00:00 2001 From: Thien Nguyen Date: Wed, 27 Oct 2021 09:06:25 +0700 Subject: [PATCH] check cart quantity --- .../Areas/ShoppingCart/Controllers/CartController.cs | 4 ++++ .../SimplCommerce.Module.ShoppingCart/Services/CartService.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Modules/SimplCommerce.Module.ShoppingCart/Areas/ShoppingCart/Controllers/CartController.cs b/src/Modules/SimplCommerce.Module.ShoppingCart/Areas/ShoppingCart/Controllers/CartController.cs index 775d74d503..54e199e0b5 100644 --- a/src/Modules/SimplCommerce.Module.ShoppingCart/Areas/ShoppingCart/Controllers/CartController.cs +++ b/src/Modules/SimplCommerce.Module.ShoppingCart/Areas/ShoppingCart/Controllers/CartController.cs @@ -101,6 +101,10 @@ public async Task List() [HttpPost("cart/update-item-quantity")] public async Task UpdateQuantity([FromBody] CartQuantityUpdate model) { + if(model.Quantity <= 0) + { + return Ok(new { Error = true, Message = _localizer["The quantity must be larger than zero"].Value }); + } var currentUser = await _workContext.GetCurrentUser(); var cart = await _cartService.GetActiveCart(currentUser.Id); diff --git a/src/Modules/SimplCommerce.Module.ShoppingCart/Services/CartService.cs b/src/Modules/SimplCommerce.Module.ShoppingCart/Services/CartService.cs index b40f951381..71cf146b63 100644 --- a/src/Modules/SimplCommerce.Module.ShoppingCart/Services/CartService.cs +++ b/src/Modules/SimplCommerce.Module.ShoppingCart/Services/CartService.cs @@ -59,6 +59,10 @@ public async Task AddToCart(long customerId, long productId, int quantit public async Task AddToCart(long customerId, long createdById, long productId, int quantity) { + if(quantity <= 0) + { + return Result.Fail(_localizer["The quantity must be larger than zero"].Value); + } var cart = await GetActiveCart(customerId, createdById); if (cart == null) {