From 45da9919459494d88c8ebb2b6c8eef87dbd6ef63 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Sun, 5 Oct 2025 17:00:04 +0100 Subject: [PATCH] Debug: Enhanced logging for variant loading investigation --- LittleShop/Services/ProductService.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/LittleShop/Services/ProductService.cs b/LittleShop/Services/ProductService.cs index 96cb544..51f6018 100644 --- a/LittleShop/Services/ProductService.cs +++ b/LittleShop/Services/ProductService.cs @@ -193,15 +193,23 @@ public class ProductService : IProductService if (product == null) return null; // Manually load variants - using fresh query to avoid Contains() json_each bug in EF Core 9 + SQLite - var variants = await _context.ProductVariants - .Where(v => v.ProductId == id && v.IsActive) - .OrderBy(v => v.SortOrder) - .ToListAsync(); + // Load ALL variants first to debug + var allVariants = await _context.ProductVariants.ToListAsync(); + Console.WriteLine($"[DEBUG GetProductById] Total variants in DB: {allVariants.Count}"); + Console.WriteLine($"[DEBUG GetProductById] Looking for ProductId: {id} (Type: {id.GetType().Name})"); - Console.WriteLine($"[DEBUG GetProductById] ProductId: {id}, Variants loaded: {variants.Count}"); + var matchingByProductId = allVariants.Where(v => v.ProductId == id).ToList(); + Console.WriteLine($"[DEBUG GetProductById] Matching by ProductId: {matchingByProductId.Count}"); + + var matchingByIsActive = allVariants.Where(v => v.IsActive).ToList(); + Console.WriteLine($"[DEBUG GetProductById] Matching by IsActive: {matchingByIsActive.Count}"); + + var variants = allVariants.Where(v => v.ProductId == id && v.IsActive).OrderBy(v => v.SortOrder).ToList(); + + Console.WriteLine($"[DEBUG GetProductById] Final variants loaded: {variants.Count}"); foreach (var v in variants.Take(3)) { - Console.WriteLine($"[DEBUG GetProductById] - {v.VariantType}: {v.Name}"); + Console.WriteLine($"[DEBUG GetProductById] - {v.VariantType}: {v.Name}, ProductId: {v.ProductId}"); } return new ProductDto