diff --git a/LittleShop/Services/ProductService.cs b/LittleShop/Services/ProductService.cs index bc61f88..9ba2bf8 100644 --- a/LittleShop/Services/ProductService.cs +++ b/LittleShop/Services/ProductService.cs @@ -22,6 +22,7 @@ public class ProductService : IProductService .Include(p => p.Category) .Include(p => p.Photos) .Include(p => p.MultiBuys.Where(v => v.IsActive)) + .Include(p => p.Variants.Where(v => v.IsActive)) .Where(p => p.IsActive) .Select(p => new ProductDto { @@ -58,6 +59,19 @@ public class ProductService : IProductService IsActive = mb.IsActive, CreatedAt = mb.CreatedAt, UpdatedAt = mb.UpdatedAt + }).ToList(), + Variants = p.Variants.Select(v => new ProductVariantDto + { + Id = v.Id, + ProductId = v.ProductId, + VariantType = v.VariantType, + Name = v.Name, + Price = v.Price, + StockLevel = v.StockLevel, + SortOrder = v.SortOrder, + IsActive = v.IsActive, + CreatedAt = v.CreatedAt, + UpdatedAt = v.UpdatedAt }).ToList() }) .ToListAsync(); @@ -69,6 +83,7 @@ public class ProductService : IProductService .Include(p => p.Category) .Include(p => p.Photos) .Include(p => p.MultiBuys.Where(v => v.IsActive)) + .Include(p => p.Variants.Where(v => v.IsActive)) .Where(p => p.IsActive && p.CategoryId == categoryId) .Select(p => new ProductDto { @@ -105,6 +120,19 @@ public class ProductService : IProductService IsActive = mb.IsActive, CreatedAt = mb.CreatedAt, UpdatedAt = mb.UpdatedAt + }).ToList(), + Variants = p.Variants.Select(v => new ProductVariantDto + { + Id = v.Id, + ProductId = v.ProductId, + VariantType = v.VariantType, + Name = v.Name, + Price = v.Price, + StockLevel = v.StockLevel, + SortOrder = v.SortOrder, + IsActive = v.IsActive, + CreatedAt = v.CreatedAt, + UpdatedAt = v.UpdatedAt }).ToList() }) .ToListAsync(); @@ -116,6 +144,7 @@ public class ProductService : IProductService .Include(p => p.Category) .Include(p => p.Photos) .Include(p => p.MultiBuys.Where(v => v.IsActive)) + .Include(p => p.Variants.Where(v => v.IsActive)) .FirstOrDefaultAsync(p => p.Id == id); if (product == null) return null; @@ -157,6 +186,19 @@ public class ProductService : IProductService IsActive = v.IsActive, CreatedAt = v.CreatedAt, UpdatedAt = v.UpdatedAt + }).ToList(), + Variants = product.Variants.OrderBy(v => v.SortOrder).Select(v => new ProductVariantDto + { + Id = v.Id, + ProductId = v.ProductId, + VariantType = v.VariantType, + Name = v.Name, + Price = v.Price, + StockLevel = v.StockLevel, + SortOrder = v.SortOrder, + IsActive = v.IsActive, + CreatedAt = v.CreatedAt, + UpdatedAt = v.UpdatedAt }).ToList() }; } diff --git a/TeleBot/TeleBot/UI/MenuBuilder.cs b/TeleBot/TeleBot/UI/MenuBuilder.cs index 6aa8c36..d96e34d 100644 --- a/TeleBot/TeleBot/UI/MenuBuilder.cs +++ b/TeleBot/TeleBot/UI/MenuBuilder.cs @@ -385,13 +385,19 @@ namespace TeleBot.UI { string variantInfo = ""; + // Show price if different from base product price + if (variant.Price.HasValue && variant.Price.Value != product.Price) + { + variantInfo = $" - £{variant.Price.Value:F2}"; + } + if (variant.StockLevel > 0) { - variantInfo = $" ({variant.StockLevel} in stock"; + variantInfo += variantInfo == "" ? $" ({variant.StockLevel} in stock" : $" ({variant.StockLevel} in stock"; } else if (variant.StockLevel == 0) { - variantInfo = " (Out of stock"; + variantInfo += variantInfo == "" ? " (Out of stock" : " (Out of stock"; } if (variant.Weight.HasValue) @@ -406,10 +412,17 @@ namespace TeleBot.UI 6 => "L", _ => "unit" }; - variantInfo += variantInfo == "" ? $" ({variant.Weight}{unitName}" : $", {variant.Weight}{unitName}"; + if (variantInfo.Contains("(")) + { + variantInfo += $", {variant.Weight}{unitName}"; + } + else + { + variantInfo += variantInfo == "" ? $" ({variant.Weight}{unitName}" : $" ({variant.Weight}{unitName}"; + } } - if (variantInfo != "") + if (variantInfo.Contains("(") && !variantInfo.EndsWith(")")) { variantInfo += ")"; }