From 870873df7dea15506adcd3307973d448f245f8b6 Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 15 Dec 2025 10:08:39 +0100 Subject: [PATCH 1/4] Added a new parameter in the GetProductToCartDetailsAsync method to show a new message in notification bar --- .../Controllers/ShoppingCartController.cs | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs b/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs index bdd1bab2ba4..2a1643e23d5 100644 --- a/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs +++ b/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs @@ -335,7 +335,7 @@ protected virtual async Task SaveItemAsync(ShoppingCartItem updatecartitem, List } protected virtual async Task GetProductToCartDetailsAsync(List addToCartWarnings, ShoppingCartType cartType, - Product product) + Product product, int updatecartitemid =0) { if (addToCartWarnings.Any()) { @@ -427,14 +427,31 @@ await _localizationService.GetResourceAsync("ShoppingCart.HeaderQuantity"), ? await RenderViewComponentToStringAsync(typeof(FlyoutShoppingCartViewComponent)) : string.Empty; - return Json(new - { - success = true, - message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheCart.Link"), - Url.RouteUrl(NopRouteNames.General.CART)), - updatetopcartsectionhtml = updateTopCartSectionHtml, - updateflyoutcartsectionhtml = updateFlyoutCartSectionHtml - }); + string message; + var cartUrl = Url.RouteUrl(NopRouteNames.General.CART); + + if (updatecartitemid > 0) + { + // FALL 1: Produkten fanns redan (Uppdatering) + message = await _localizationService.GetResourceAsync("Products.ProductHasBeenUpdatedInTheCart"); + + // Fallback om du inte lagt in resursen i admin än: + if (string.IsNullOrEmpty(message)) + message = $"The product has been updated in your shopping cart."; + } + else + { + // FALL 2: Ny produkt (Standard) + message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheCart.Link"), cartUrl); + } + + return Json(new + { + success = true, + message = message, + updatetopcartsectionhtml = updateTopCartSectionHtml, + updateflyoutcartsectionhtml = updateFlyoutCartSectionHtml + }); } } } @@ -827,7 +844,8 @@ public virtual async Task AddProductToCart_Details(int productId, await SaveItemAsync(updatecartitem, addToCartWarnings, product, cartType, attributes, customerEnteredPriceConverted, rentalStartDate, rentalEndDate, quantity); //return result - return await GetProductToCartDetailsAsync(addToCartWarnings, cartType, product); + // Här skickar vi med updatecartitemid (som du såg var "14" i din debug) + return await GetProductToCartDetailsAsync(addToCartWarnings, cartType, product, updatecartitemid); } //handle product attribute selection event. this way we return new price, overridden gtin/sku/mpn From aaaa9b10323583a5b51de10e6c70e325af798e18 Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 15 Dec 2025 12:54:28 +0100 Subject: [PATCH 2/4] New text in notification bar is now visible --- .../Nop.Web/Controllers/ShoppingCartController.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs b/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs index 2a1643e23d5..70f2c77effa 100644 --- a/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs +++ b/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs @@ -427,23 +427,19 @@ await _localizationService.GetResourceAsync("ShoppingCart.HeaderQuantity"), ? await RenderViewComponentToStringAsync(typeof(FlyoutShoppingCartViewComponent)) : string.Empty; - string message; + string message = ""; var cartUrl = Url.RouteUrl(NopRouteNames.General.CART); if (updatecartitemid > 0) { // FALL 1: Produkten fanns redan (Uppdatering) - message = await _localizationService.GetResourceAsync("Products.ProductHasBeenUpdatedInTheCart"); + message = await _localizationService.GetResourceAsync("products.producthasbeenupdatedinthecart"); // Fallback om du inte lagt in resursen i admin än: if (string.IsNullOrEmpty(message)) message = $"The product has been updated in your shopping cart."; } - else - { - // FALL 2: Ny produkt (Standard) - message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheCart.Link"), cartUrl); - } + return Json(new { From 3f02cbf176e333377a12ca2a2b57b08cdfbc49d9 Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 15 Dec 2025 14:01:43 +0100 Subject: [PATCH 3/4] Cleaned up the Controller --- .../Controllers/ShoppingCartController.cs | 382 +++++++++--------- 1 file changed, 186 insertions(+), 196 deletions(-) diff --git a/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs b/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs index 70f2c77effa..e67a8165fdc 100644 --- a/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs +++ b/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs @@ -189,95 +189,95 @@ protected virtual async Task ParseAndSaveCheckoutAttributesAsync(IList 0) - attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, - attribute, selectedAttributeId.ToString()); + var ctrlAttributes = form[controlId]; + if (!StringValues.IsNullOrEmpty(ctrlAttributes)) + { + var selectedAttributeId = int.Parse(ctrlAttributes); + if (selectedAttributeId > 0) + attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, + attribute, selectedAttributeId.ToString()); + } } - } - break; + break; case AttributeControlType.Checkboxes: - { - var cblAttributes = form[controlId]; - if (!StringValues.IsNullOrEmpty(cblAttributes)) { - foreach (var item in cblAttributes.ToString().Split(_separator, StringSplitOptions.RemoveEmptyEntries)) + var cblAttributes = form[controlId]; + if (!StringValues.IsNullOrEmpty(cblAttributes)) { - var selectedAttributeId = int.Parse(item); - if (selectedAttributeId > 0) - attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, - attribute, selectedAttributeId.ToString()); + foreach (var item in cblAttributes.ToString().Split(_separator, StringSplitOptions.RemoveEmptyEntries)) + { + var selectedAttributeId = int.Parse(item); + if (selectedAttributeId > 0) + attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, + attribute, selectedAttributeId.ToString()); + } } } - } - break; + break; case AttributeControlType.ReadonlyCheckboxes: - { - //load read-only (already server-side selected) values - var attributeValues = await _checkoutAttributeService.GetAttributeValuesAsync(attribute.Id); - foreach (var selectedAttributeId in attributeValues - .Where(v => v.IsPreSelected) - .Select(v => v.Id) - .ToList()) { - attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, - attribute, selectedAttributeId.ToString()); + //load read-only (already server-side selected) values + var attributeValues = await _checkoutAttributeService.GetAttributeValuesAsync(attribute.Id); + foreach (var selectedAttributeId in attributeValues + .Where(v => v.IsPreSelected) + .Select(v => v.Id) + .ToList()) + { + attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, + attribute, selectedAttributeId.ToString()); + } } - } - break; + break; case AttributeControlType.TextBox: case AttributeControlType.MultilineTextbox: - { - var ctrlAttributes = form[controlId]; - if (!StringValues.IsNullOrEmpty(ctrlAttributes)) { - var enteredText = ctrlAttributes.ToString().Trim(); - attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, - attribute, enteredText); + var ctrlAttributes = form[controlId]; + if (!StringValues.IsNullOrEmpty(ctrlAttributes)) + { + var enteredText = ctrlAttributes.ToString().Trim(); + attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, + attribute, enteredText); + } } - } - break; + break; case AttributeControlType.Datepicker: - { - var date = form[controlId + "_day"]; - var month = form[controlId + "_month"]; - var year = form[controlId + "_year"]; - DateTime? selectedDate = null; - try - { - selectedDate = new DateTime(int.Parse(year), int.Parse(month), int.Parse(date)); - } - catch { - // ignored - } + var date = form[controlId + "_day"]; + var month = form[controlId + "_month"]; + var year = form[controlId + "_year"]; + DateTime? selectedDate = null; + try + { + selectedDate = new DateTime(int.Parse(year), int.Parse(month), int.Parse(date)); + } + catch + { + // ignored + } - if (selectedDate.HasValue) - attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, - attribute, selectedDate.Value.ToString("D")); - } + if (selectedDate.HasValue) + attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, + attribute, selectedDate.Value.ToString("D")); + } - break; + break; case AttributeControlType.FileUpload: - { - _ = Guid.TryParse(form[controlId], out var downloadGuid); - var download = await _downloadService.GetDownloadByGuidAsync(downloadGuid); - if (download != null) { - attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, - attribute, download.DownloadGuid.ToString()); + _ = Guid.TryParse(form[controlId], out var downloadGuid); + var download = await _downloadService.GetDownloadByGuidAsync(downloadGuid); + if (download != null) + { + attributesXml = _checkoutAttributeParser.AddAttribute(attributesXml, + attribute, download.DownloadGuid.ToString()); + } } - } - break; + break; default: break; } @@ -335,7 +335,7 @@ protected virtual async Task SaveItemAsync(ShoppingCartItem updatecartitem, List } protected virtual async Task GetProductToCartDetailsAsync(List addToCartWarnings, ShoppingCartType cartType, - Product product, int updatecartitemid =0) + Product product, int updateCartItemId = 0) { if (addToCartWarnings.Any()) { @@ -354,101 +354,92 @@ protected virtual async Task GetProductToCartDetailsAsync(List item.Quantity)); + var updateTopWishlistSectionHtml = string.Format( + await _localizationService.GetResourceAsync("Wishlist.HeaderQuantity"), + shoppingCarts.Sum(item => item.Quantity)); - var customWishlists = await _customWishlistService.GetAllCustomWishlistsAsync(customer.Id); - var isGuest = await _customerService.IsGuestAsync(customer); + var customWishlists = await _customWishlistService.GetAllCustomWishlistsAsync(customer.Id); + var isGuest = await _customerService.IsGuestAsync(customer); - if (!isGuest && customWishlists.Any()) - { - var onclick = $"showMoveToWishlistModal({product.Id}); return false;"; - return Json(new + if (!isGuest && customWishlists.Any()) { - success = true, - message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheWishlistAndMoved.Link"), wishlistRouteUrl, onclick), - updatetopwishlistsectionhtml = updateTopWishlistSectionHtml - }); - } - else - { - return Json(new + var onclick = $"showMoveToWishlistModal({product.Id}); return false;"; + return Json(new + { + success = true, + message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheWishlistAndMoved.Link"), wishlistRouteUrl, onclick), + updatetopwishlistsectionhtml = updateTopWishlistSectionHtml + }); + } + else { - success = true, - message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheWishlist.Link"), wishlistRouteUrl), - updatetopwishlistsectionhtml = updateTopWishlistSectionHtml - }); + return Json(new + { + success = true, + message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheWishlist.Link"), wishlistRouteUrl), + updatetopwishlistsectionhtml = updateTopWishlistSectionHtml + }); + } } - } case ShoppingCartType.ShoppingCart: default: - { - //activity log - await _customerActivityService.InsertActivityAsync("PublicStore.AddToShoppingCart", - string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.AddToShoppingCart"), product.Name), product); - - if (_shoppingCartSettings.DisplayCartAfterAddingProduct) { - //redirect to the shopping cart page - return Json(new - { - redirect = Url.RouteUrl(NopRouteNames.General.CART) - }); - } + //activity log + await _customerActivityService.InsertActivityAsync("PublicStore.AddToShoppingCart", + string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.AddToShoppingCart"), product.Name), product); - //display notification message and update appropriate blocks - var shoppingCarts = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id); + if (_shoppingCartSettings.DisplayCartAfterAddingProduct) + { + //redirect to the shopping cart page + return Json(new + { + redirect = Url.RouteUrl(NopRouteNames.General.CART) + }); + } - var updateTopCartSectionHtml = string.Format( - await _localizationService.GetResourceAsync("ShoppingCart.HeaderQuantity"), - shoppingCarts.Sum(item => item.Quantity)); + //display notification message and update appropriate blocks + var shoppingCarts = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id); - var updateFlyoutCartSectionHtml = _shoppingCartSettings.MiniShoppingCartEnabled - ? await RenderViewComponentToStringAsync(typeof(FlyoutShoppingCartViewComponent)) - : string.Empty; + var updateTopCartSectionHtml = string.Format( + await _localizationService.GetResourceAsync("ShoppingCart.HeaderQuantity"), + shoppingCarts.Sum(item => item.Quantity)); - string message = ""; - var cartUrl = Url.RouteUrl(NopRouteNames.General.CART); + var updateFlyoutCartSectionHtml = _shoppingCartSettings.MiniShoppingCartEnabled + ? await RenderViewComponentToStringAsync(typeof(FlyoutShoppingCartViewComponent)) + : string.Empty; - if (updatecartitemid > 0) - { - // FALL 1: Produkten fanns redan (Uppdatering) - message = await _localizationService.GetResourceAsync("products.producthasbeenupdatedinthecart"); + var updateProductMessage = updateCartItemId > 0 + ? await _localizationService.GetResourceAsync("Products.ProductHasBeenUpdatedInTheCart") + : string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheCart.Link"), Url.RouteUrl(NopRouteNames.General.CART)); - // Fallback om du inte lagt in resursen i admin än: - if (string.IsNullOrEmpty(message)) - message = $"The product has been updated in your shopping cart."; - } - return Json(new { success = true, - message = message, + message = updateProductMessage, updatetopcartsectionhtml = updateTopCartSectionHtml, updateflyoutcartsectionhtml = updateFlyoutCartSectionHtml }); - } + } } } @@ -675,86 +666,86 @@ public virtual async Task AddProductToCart_Catalog(int productId, switch (cartType) { case ShoppingCartType.Wishlist: - { + { - var wishlistRouteUrl = Url.RouteUrl(NopRouteNames.General.WISHLIST); - //activity log - await _customerActivityService.InsertActivityAsync("PublicStore.AddToWishlist", - string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.AddToWishlist"), product.Name), product); + var wishlistRouteUrl = Url.RouteUrl(NopRouteNames.General.WISHLIST); + //activity log + await _customerActivityService.InsertActivityAsync("PublicStore.AddToWishlist", + string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.AddToWishlist"), product.Name), product); - if (_shoppingCartSettings.DisplayWishlistAfterAddingProduct || forceredirection) - { - //redirect to the wishlist page - return Json(new + if (_shoppingCartSettings.DisplayWishlistAfterAddingProduct || forceredirection) { - redirect = wishlistRouteUrl - }); - } + //redirect to the wishlist page + return Json(new + { + redirect = wishlistRouteUrl + }); + } - //display notification message and update appropriate blocks - var shoppingCarts = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.Wishlist, store.Id); + //display notification message and update appropriate blocks + var shoppingCarts = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.Wishlist, store.Id); - var updatetopwishlistsectionhtml = string.Format(await _localizationService.GetResourceAsync("Wishlist.HeaderQuantity"), - shoppingCarts.Sum(item => item.Quantity)); + var updatetopwishlistsectionhtml = string.Format(await _localizationService.GetResourceAsync("Wishlist.HeaderQuantity"), + shoppingCarts.Sum(item => item.Quantity)); - var customWishlists = await _customWishlistService.GetAllCustomWishlistsAsync(customer.Id); - var isGuest = await _customerService.IsGuestAsync(customer); + var customWishlists = await _customWishlistService.GetAllCustomWishlistsAsync(customer.Id); + var isGuest = await _customerService.IsGuestAsync(customer); - if (!isGuest && customWishlists.Any()) - { - var onclick = $"showMoveToWishlistModal({productId}); return false;"; - return Json(new + if (!isGuest && customWishlists.Any()) { - success = true, - message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheWishlistAndMoved.Link"), wishlistRouteUrl, onclick), - updatetopwishlistsectionhtml - }); - } - else - { - return Json(new + var onclick = $"showMoveToWishlistModal({productId}); return false;"; + return Json(new + { + success = true, + message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheWishlistAndMoved.Link"), wishlistRouteUrl, onclick), + updatetopwishlistsectionhtml + }); + } + else { - success = true, - message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheWishlist.Link"), wishlistRouteUrl), - updatetopwishlistsectionhtml - }); + return Json(new + { + success = true, + message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheWishlist.Link"), wishlistRouteUrl), + updatetopwishlistsectionhtml + }); + } } - } case ShoppingCartType.ShoppingCart: default: - { - //activity log - await _customerActivityService.InsertActivityAsync("PublicStore.AddToShoppingCart", - string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.AddToShoppingCart"), product.Name), product); - - if (_shoppingCartSettings.DisplayCartAfterAddingProduct || forceredirection) { - //redirect to the shopping cart page - return Json(new + //activity log + await _customerActivityService.InsertActivityAsync("PublicStore.AddToShoppingCart", + string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.AddToShoppingCart"), product.Name), product); + + if (_shoppingCartSettings.DisplayCartAfterAddingProduct || forceredirection) { - redirect = Url.RouteUrl(NopRouteNames.General.CART) - }); - } + //redirect to the shopping cart page + return Json(new + { + redirect = Url.RouteUrl(NopRouteNames.General.CART) + }); + } - //display notification message and update appropriate blocks - var shoppingCarts = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id); + //display notification message and update appropriate blocks + var shoppingCarts = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id); - var updatetopcartsectionhtml = string.Format(await _localizationService.GetResourceAsync("ShoppingCart.HeaderQuantity"), - shoppingCarts.Sum(item => item.Quantity)); + var updatetopcartsectionhtml = string.Format(await _localizationService.GetResourceAsync("ShoppingCart.HeaderQuantity"), + shoppingCarts.Sum(item => item.Quantity)); - var updateflyoutcartsectionhtml = _shoppingCartSettings.MiniShoppingCartEnabled - ? await RenderViewComponentToStringAsync(typeof(FlyoutShoppingCartViewComponent)) - : string.Empty; + var updateflyoutcartsectionhtml = _shoppingCartSettings.MiniShoppingCartEnabled + ? await RenderViewComponentToStringAsync(typeof(FlyoutShoppingCartViewComponent)) + : string.Empty; - return Json(new - { - success = true, - message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheCart.Link"), Url.RouteUrl(NopRouteNames.General.CART)), - updatetopcartsectionhtml, - updateflyoutcartsectionhtml - }); - } + return Json(new + { + success = true, + message = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheCart.Link"), Url.RouteUrl(NopRouteNames.General.CART)), + updatetopcartsectionhtml, + updateflyoutcartsectionhtml + }); + } } } @@ -839,8 +830,7 @@ public virtual async Task AddProductToCart_Details(int productId, await SaveItemAsync(updatecartitem, addToCartWarnings, product, cartType, attributes, customerEnteredPriceConverted, rentalStartDate, rentalEndDate, quantity); - //return result - // Här skickar vi med updatecartitemid (som du såg var "14" i din debug) + return await GetProductToCartDetailsAsync(addToCartWarnings, cartType, product, updatecartitemid); } From 4185bdc49e032962c1b3c91de869bc1552dbc57b Mon Sep 17 00:00:00 2001 From: Emma Date: Tue, 16 Dec 2025 15:38:54 +0100 Subject: [PATCH 4/4] Implemented logic for updated notification and wrote test for it --- .../Controllers/ShoppingCartController.cs | 26 ++++++-- .../ShoppingCartControllerTests.cs | 64 +++++++++++++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/Tests/Nop.Tests/Nop.Web.Tests/Public/Controllers/ShoppingCartControllerTests.cs diff --git a/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs b/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs index e67a8165fdc..ea110db6fda 100644 --- a/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs +++ b/src/Presentation/Nop.Web/Controllers/ShoppingCartController.cs @@ -335,7 +335,7 @@ protected virtual async Task SaveItemAsync(ShoppingCartItem updatecartitem, List } protected virtual async Task GetProductToCartDetailsAsync(List addToCartWarnings, ShoppingCartType cartType, - Product product, int updateCartItemId = 0) + Product product, int updateCartItemId = 0) { if (addToCartWarnings.Any()) { @@ -427,15 +427,22 @@ await _localizationService.GetResourceAsync("ShoppingCart.HeaderQuantity"), ? await RenderViewComponentToStringAsync(typeof(FlyoutShoppingCartViewComponent)) : string.Empty; - var updateProductMessage = updateCartItemId > 0 - ? await _localizationService.GetResourceAsync("Products.ProductHasBeenUpdatedInTheCart") - : string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheCart.Link"), Url.RouteUrl(NopRouteNames.General.CART)); + + var addedText = string.Format(await _localizationService.GetResourceAsync("Products.ProductHasBeenAddedToTheCart.Link"), Url.RouteUrl(NopRouteNames.General.CART)); + var updatedText = await _localizationService.GetResourceAsync("Products.ProductHasBeenUpdatedInTheCart"); + + + if (string.IsNullOrEmpty(updatedText)) + updatedText = "Product updated in cart."; + + + var message = GetCartStatusMessage(updateCartItemId, addedText, updatedText); return Json(new { success = true, - message = updateProductMessage, + message = message, updatetopcartsectionhtml = updateTopCartSectionHtml, updateflyoutcartsectionhtml = updateFlyoutCartSectionHtml }); @@ -1925,4 +1932,13 @@ public virtual async Task DeleteWishlist(int wishlistId) } #endregion + + public static string GetCartStatusMessage(int updateCartItemId, string addedResource, string updatedResource) + { + if (updateCartItemId > 0) + { + return updatedResource; + } + return addedResource; + } } \ No newline at end of file diff --git a/src/Tests/Nop.Tests/Nop.Web.Tests/Public/Controllers/ShoppingCartControllerTests.cs b/src/Tests/Nop.Tests/Nop.Web.Tests/Public/Controllers/ShoppingCartControllerTests.cs new file mode 100644 index 00000000000..5130e46107a --- /dev/null +++ b/src/Tests/Nop.Tests/Nop.Web.Tests/Public/Controllers/ShoppingCartControllerTests.cs @@ -0,0 +1,64 @@ +using NUnit.Framework; + +using Nop.Web.Controllers; +using NUnit.Framework.Legacy; + +namespace Nop.Tests.Nop.Web.Tests.Public.Controllers + +{ + + [TestFixture] + + public class ShoppingCartControllerTests + + { + + [Test] + + public void GetCartStatusMessage_Should_Return_Updated_When_Id_Is_Positive() + + { + + // Arrange + + int id = 14; + string addedText = "Added logic"; + + string updatedText = "Updated logic"; + + // Act + string result = ShoppingCartController.GetCartStatusMessage(id, addedText, updatedText); + + // Assert + + ClassicAssert.AreEqual("Updated logic", result, "If ID is 14 we shall get the Updated-text"); + + } + + [Test] + + public void GetCartStatusMessage_Should_Return_Added_When_Id_Is_Zero() + + { + + // Arrange + + int id = 0; + + string addedText = "Added logic"; + + string updatedText = "Updated logic"; + + // Act + + string result = ShoppingCartController.GetCartStatusMessage(id, addedText, updatedText); + + // Assert + + ClassicAssert.AreEqual("Added logic", result, "If ID is 0 we shall get the Added-text"); + + } + + } + +} \ No newline at end of file