From 2c5815510d70d3ff0cd2e45daa5b814061a5aeb8 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Wed, 8 Oct 2025 17:48:05 +0100 Subject: [PATCH] Fix: Display variant price and stock directly in Product Edit page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem:** - Variant price overrides and stock quantities were hidden in collapsible panels in the Product Edit page - The Edit page was showing the VariantCollections system (VariantsJson) instead of the actual ProductVariant records created by text import - User had to expand each variant panel to see price and stock values **Solution:** 1. **ProductsController.cs (Lines 101-103):** - Added call to GetProductVariantsAsync() to load actual variant records - Added ViewData["ProductVariants"] to pass data to view 2. **Edit.cshtml (Lines 320-413):** - Added new collapsible section "Product Variants" - Displays variants in a table with directly visible columns: * Name, Type, Price, Stock Level, Sort Order, Status - No hidden panels - all information visible at a glance - Added quick summary with total variants, stock, and price range - Includes helpful links to ProductVariants management page **Technical Details:** - Price displays in green with £ symbol when override exists - Stock shows color-coded badges (green=in stock, red=out of stock) - Section only appears if variants exist (conditional rendering) - Expanded by default (aria-expanded="true") for immediate visibility **Impact:** - User can now see all variant prices and stock quantities immediately - No need to click/expand individual variant panels - Better UX for products imported via text import format - Maintains separation between VariantCollections system and ProductVariants 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Admin/Controllers/ProductsController.cs | 4 + .../Areas/Admin/Views/Products/Edit.cshtml | 95 +++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/LittleShop/Areas/Admin/Controllers/ProductsController.cs b/LittleShop/Areas/Admin/Controllers/ProductsController.cs index fe03970..d821c90 100644 --- a/LittleShop/Areas/Admin/Controllers/ProductsController.cs +++ b/LittleShop/Areas/Admin/Controllers/ProductsController.cs @@ -98,6 +98,10 @@ public class ProductsController : Controller var productMultiBuys = await _productService.GetProductMultiBuysAsync(id); ViewData["ProductMultiBuys"] = productMultiBuys; + // Load product variants + var productVariants = await _productService.GetProductVariantsAsync(id); + ViewData["ProductVariants"] = productVariants; + // TODO: Add ReviewService injection and retrieve actual reviews // For now, providing mock review data for demonstration ViewData["ProductReviews"] = new[] diff --git a/LittleShop/Areas/Admin/Views/Products/Edit.cshtml b/LittleShop/Areas/Admin/Views/Products/Edit.cshtml index 697273e..3744982 100644 --- a/LittleShop/Areas/Admin/Views/Products/Edit.cshtml +++ b/LittleShop/Areas/Admin/Views/Products/Edit.cshtml @@ -317,6 +317,101 @@ + + @{ + var productVariants = ViewData["ProductVariants"] as IEnumerable; + } + @if (productVariants != null && productVariants.Any()) + { +
+
+
+ +
+
+
+

+ These variants were imported via text import format. + To manage them, use the Product Variants page + or re-import via Text Import. +

+ +
+ + + + + + + + + + + + + @foreach (var variant in productVariants.OrderBy(v => v.SortOrder)) + { + + + + + + + + + } + +
NameTypePriceStock LevelSort OrderStatus
@variant.Name + @variant.VariantType + + @if (variant.Price.HasValue) + { + £@variant.Price.Value.ToString("F2") + } + else + { + £@Model?.Price.ToString("F2") (base) + } + + @if (variant.StockLevel > 0) + { + @variant.StockLevel in stock + } + else + { + Out of stock + } + @variant.SortOrder + @if (variant.IsActive) + { + Active + } + else + { + Inactive + } +
+
+ +
+ Quick Summary: + Total variants: @productVariants.Count() | + Total stock: @productVariants.Sum(v => v.StockLevel) units | + Price range: £@productVariants.Where(v => v.Price.HasValue).Min(v => v.Price ?? 0).ToString("F2") - £@productVariants.Where(v => v.Price.HasValue).Max(v => v.Price ?? 0).ToString("F2") +
+
+
+
+ } +