Enables individual variants to have their own prices, overriding the base product price. **Database Changes:** - Added Price (decimal?, nullable) to ProductVariants table - Added ProductVariantId to OrderItems table with foreign key relationship - Created index on OrderItems.ProductVariantId for performance **API Changes:** - ProductVariantDto: Added Price field - CreateProductVariantDto: Added Price field with validation - UpdateProductVariantDto: Added Price field - OrderItemDto: Added ProductVariantId and ProductVariantName - CreateOrderItemDto: Added ProductVariantId **Business Logic:** - OrderService: Variant price overrides base price (but multi-buy takes precedence) - ProductService: All variant CRUD operations support Price field **Admin UI:** - CreateVariant: Price input with £ symbol and base price placeholder - EditVariant: Price editing with £ symbol - ProductVariants list: Shows variant price or "(base)" indicator **Client Library:** - Updated all DTOs to match server-side changes - Full support for variant pricing in order creation **Migration:** - EF Core migration: 20251003173458_AddVariantPricing - Backward compatible: NULL values supported for existing data **Use Case:** Products with size/color variants can now have different prices: - Small T-shirt: £15.00 (variant override) - Medium T-shirt: £18.00 (uses base price) - Large T-shirt: £20.00 (variant override) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
namespace LittleShop.Client.Models;
|
|
|
|
public class Product
|
|
{
|
|
public Guid Id { get; set; }
|
|
public string Name { get; set; } = string.Empty;
|
|
public string? Description { get; set; }
|
|
public decimal Price { get; set; }
|
|
public decimal Weight { get; set; }
|
|
public int WeightUnit { get; set; }
|
|
public Guid CategoryId { get; set; }
|
|
public string? CategoryName { get; set; }
|
|
public bool IsActive { get; set; }
|
|
public List<ProductPhoto> Photos { get; set; } = new();
|
|
public List<ProductMultiBuy> MultiBuys { get; set; } = new();
|
|
public List<ProductVariant> Variants { get; set; } = new();
|
|
public DateTime CreatedAt { get; set; }
|
|
public DateTime UpdatedAt { get; set; }
|
|
}
|
|
|
|
public class ProductPhoto
|
|
{
|
|
public Guid Id { get; set; }
|
|
public string Url { get; set; } = string.Empty;
|
|
public string? AltText { get; set; }
|
|
public int SortOrder { get; set; }
|
|
}
|
|
|
|
public class ProductMultiBuy
|
|
{
|
|
public Guid Id { get; set; }
|
|
public Guid ProductId { get; set; }
|
|
public string Name { get; set; } = string.Empty;
|
|
public string? Description { get; set; }
|
|
public int Quantity { get; set; }
|
|
public decimal Price { get; set; }
|
|
public decimal PricePerUnit { get; set; }
|
|
public int SortOrder { get; set; }
|
|
public bool IsActive { get; set; }
|
|
}
|
|
|
|
public class ProductVariant
|
|
{
|
|
public Guid Id { get; set; }
|
|
public Guid ProductId { get; set; }
|
|
public string Name { get; set; } = string.Empty; // e.g., "Red", "Blue", "Vanilla"
|
|
public string VariantType { get; set; } = "Standard"; // e.g., "Color", "Flavor"
|
|
public int SortOrder { get; set; }
|
|
public int StockLevel { get; set; }
|
|
public decimal? Weight { get; set; } // Optional: override product weight
|
|
public int? WeightUnit { get; set; } // Optional: override product weight unit
|
|
public decimal? Price { get; set; } // Optional: override product price (if null, uses product.Price)
|
|
public bool IsActive { get; set; }
|
|
} |