Add variant collections system and enhance ProductVariant with weight/stock tracking

This commit introduces a comprehensive variant management system and enhances
the existing ProductVariant model with per-variant weight overrides and stock
tracking, integrated across Admin Panel and TeleBot.

Features Added:
- Variant Collections: Reusable variant templates (e.g., "Standard Sizes")
- Admin UI for managing variant collections (CRUD operations)
- Dynamic variant editor with JavaScript-based UI
- Per-variant weight and weight unit overrides
- Per-variant stock level tracking
- SalesLedger model for financial tracking

ProductVariant Enhancements:
- Added Weight (decimal, nullable) field for variant-specific weights
- Added WeightUnit (enum, nullable) field for variant-specific units
- Maintains backward compatibility with product-level weights

TeleBot Integration:
- Enhanced variant selection UI to display stock levels
- Shows weight information with proper unit conversion (µg, g, oz, lb, ml, L)
- Compact button format: "Medium (15 in stock, 350g)"
- Real-time stock availability display

Database Migrations:
- 20250928014850_AddVariantCollectionsAndSalesLedger
- 20250928155814_AddWeightToProductVariants

Technical Changes:
- Updated Product model to support VariantCollectionId and VariantsJson
- Extended ProductService with variant collection operations
- Enhanced OrderService to handle variant-specific pricing and weights
- Updated LittleShop.Client DTOs to match server models
- Added JavaScript dynamic variant form builder

Files Modified: 15
Files Added: 17
Lines Changed: ~2000

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
sysadmin
2025-09-28 17:03:09 +01:00
parent 191a9f27f2
commit eb87148c63
32 changed files with 5884 additions and 102 deletions

View File

@@ -24,9 +24,13 @@ public class Product
public ProductWeightUnit WeightUnit { get; set; } = ProductWeightUnit.Kilogram;
public int StockQuantity { get; set; } = 0;
public Guid CategoryId { get; set; }
public Guid? VariantCollectionId { get; set; }
public string? VariantsJson { get; set; }
public bool IsActive { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
@@ -35,9 +39,11 @@ public class Product
// Navigation properties
public virtual Category Category { get; set; } = null!;
public virtual VariantCollection? VariantCollection { get; set; }
public virtual ICollection<ProductPhoto> Photos { get; set; } = new List<ProductPhoto>();
public virtual ICollection<ProductMultiBuy> MultiBuys { get; set; } = new List<ProductMultiBuy>();
public virtual ICollection<ProductVariant> Variants { get; set; } = new List<ProductVariant>();
public virtual ICollection<SalesLedger> SalesLedgers { get; set; } = new List<SalesLedger>();
public virtual ICollection<BotActivity> Activities { get; set; } = new List<BotActivity>();
public virtual ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
public virtual ICollection<Review> Reviews { get; set; } = new List<Review>();

View File

@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using LittleShop.Enums;
namespace LittleShop.Models;
@@ -22,6 +23,10 @@ public class ProductVariant
public int StockLevel { get; set; } = 0; // Optional: track stock per variant
public decimal? Weight { get; set; } // Optional: override product weight for this variant
public ProductWeightUnit? WeightUnit { get; set; } // Optional: override product weight unit for this variant
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

View File

@@ -0,0 +1,36 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace LittleShop.Models;
public class SalesLedger
{
[Key]
public Guid Id { get; set; }
public Guid OrderId { get; set; }
public Guid ProductId { get; set; }
[StringLength(200)]
public string ProductName { get; set; } = string.Empty;
public int Quantity { get; set; }
[Column(TypeName = "decimal(18,2)")]
public decimal SalePriceFiat { get; set; }
[StringLength(3)]
public string FiatCurrency { get; set; } = "GBP";
[Column(TypeName = "decimal(18,8)")]
public decimal? SalePriceBTC { get; set; }
[StringLength(50)]
public string? Cryptocurrency { get; set; }
public DateTime SoldAt { get; set; } = DateTime.UtcNow;
public virtual Order Order { get; set; } = null!;
public virtual Product Product { get; set; } = null!;
}

View File

@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace LittleShop.Models;
public class VariantCollection
{
[Key]
public Guid Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; } = string.Empty;
public string PropertiesJson { get; set; } = "[]";
public bool IsActive { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
}