From 3a2ef481b0248dc215fa1be0d3ba4f09d91c272c Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Sun, 5 Oct 2025 16:39:46 +0100 Subject: [PATCH] Debug: Add console logging to variant loading --- LittleShop/Services/ProductService.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/LittleShop/Services/ProductService.cs b/LittleShop/Services/ProductService.cs index 9a09ca8..8f9df64 100644 --- a/LittleShop/Services/ProductService.cs +++ b/LittleShop/Services/ProductService.cs @@ -25,16 +25,28 @@ public class ProductService : IProductService .Where(p => p.IsActive) .ToListAsync(); + Console.WriteLine($"[DEBUG] Loaded {products.Count} products"); + // Manually load variants for all products var productIds = products.Select(p => p.Id).ToList(); + Console.WriteLine($"[DEBUG] Product IDs: {string.Join(", ", productIds.Select(id => id.ToString()))}"); + var allVariants = await _context.ProductVariants .Where(v => productIds.Contains(v.ProductId)) .ToListAsync(); + Console.WriteLine($"[DEBUG] Loaded {allVariants.Count} total variants from database"); + foreach (var v in allVariants.Take(5)) + { + Console.WriteLine($"[DEBUG] - Variant: {v.Id}, ProductId: {v.ProductId}, Type: {v.VariantType}, Name: {v.Name}"); + } + // Group variants by ProductId for quick lookup var variantsByProduct = allVariants.GroupBy(v => v.ProductId) .ToDictionary(g => g.Key, g => g.ToList()); + Console.WriteLine($"[DEBUG] Grouped variants into {variantsByProduct.Count} product groups"); + return products.Select(p => new ProductDto { Id = p.Id,