From e17370bdf6089e8a8d78d11e9b16d3d9b6caaf7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Murat=20O=C4=9Fuz?= <151613636+muratoguzz@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:37:35 +0300 Subject: [PATCH] Fix cart item count display in CartSummaryViewComponent Updated the Invoke method to correctly display the total quantity of items in the cart instead of just the distinct item count. --- Store/StoreApp/Components/CartSummaryViewComponent.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Store/StoreApp/Components/CartSummaryViewComponent.cs b/Store/StoreApp/Components/CartSummaryViewComponent.cs index 35cecd9..75af1c9 100644 --- a/Store/StoreApp/Components/CartSummaryViewComponent.cs +++ b/Store/StoreApp/Components/CartSummaryViewComponent.cs @@ -6,6 +6,7 @@ namespace StoreApp.Components public class CartSummaryViewComponent : ViewComponent { private readonly Cart _cart; + private int productQuantity { get; set; } public CartSummaryViewComponent(Cart cartService) { _cart = cartService; @@ -13,7 +14,12 @@ public CartSummaryViewComponent(Cart cartService) public string Invoke() { - return _cart.Lines.Count().ToString(); + foreach (var line in _cart.Lines) + { + productQuantity += line.Quantity; + } + + return productQuantity.ToString(); } } -} \ No newline at end of file +}