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

@@ -29,6 +29,8 @@ public class LittleShopContext : DbContext
public DbSet<Review> Reviews { get; set; }
public DbSet<BotContact> BotContacts { get; set; }
public DbSet<SystemSetting> SystemSettings { get; set; }
public DbSet<VariantCollection> VariantCollections { get; set; }
public DbSet<SalesLedger> SalesLedgers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -310,5 +312,31 @@ public class LittleShopContext : DbContext
entity.HasKey(e => e.Key);
entity.HasIndex(e => e.Key).IsUnique();
});
// VariantCollection entity
modelBuilder.Entity<VariantCollection>(entity =>
{
entity.HasIndex(e => e.Name);
entity.HasIndex(e => e.IsActive);
});
// SalesLedger entity
modelBuilder.Entity<SalesLedger>(entity =>
{
entity.HasOne(sl => sl.Order)
.WithMany()
.HasForeignKey(sl => sl.OrderId)
.OnDelete(DeleteBehavior.Restrict);
entity.HasOne(sl => sl.Product)
.WithMany(p => p.SalesLedgers)
.HasForeignKey(sl => sl.ProductId)
.OnDelete(DeleteBehavior.Restrict);
entity.HasIndex(e => e.OrderId);
entity.HasIndex(e => e.ProductId);
entity.HasIndex(e => e.SoldAt);
entity.HasIndex(e => new { e.ProductId, e.SoldAt });
});
}
}