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,