Implement product multi-buys and variants system

Major restructuring of product variations:
- Renamed ProductVariation to ProductMultiBuy for quantity-based pricing (e.g., "3 for £25")
- Added new ProductVariant model for string-based options (colors, flavors)
- Complete separation of multi-buy pricing from variant selection

Features implemented:
- Multi-buy deals with automatic price-per-unit calculation
- Product variants for colors/flavors/sizes with stock tracking
- TeleBot checkout supports both multi-buys and variant selection
- Shopping cart correctly calculates multi-buy bundle prices
- Order system tracks selected variants and multi-buy choices
- Real-time bot activity monitoring with SignalR
- Public bot directory page with QR codes for Telegram launch
- Admin dashboard shows multi-buy and variant metrics

Technical changes:
- Updated all DTOs, services, and controllers
- Fixed cart total calculation for multi-buy bundles
- Comprehensive test coverage for new functionality
- All existing tests passing with new features

Database changes:
- Migrated ProductVariations to ProductMultiBuys
- Added ProductVariants table
- Updated OrderItems to track variants

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-21 00:30:12 +01:00
parent 7683b7dfe5
commit 034b8facee
46 changed files with 3190 additions and 332 deletions

View File

@@ -0,0 +1,82 @@
using System.ComponentModel.DataAnnotations;
namespace LittleShop.DTOs;
public class BotActivityDto
{
public Guid Id { get; set; }
public Guid BotId { get; set; }
public string BotName { get; set; } = string.Empty;
public string SessionIdentifier { get; set; } = string.Empty;
public string UserDisplayName { get; set; } = string.Empty;
public string ActivityType { get; set; } = string.Empty;
public string ActivityDescription { get; set; } = string.Empty;
public Guid? ProductId { get; set; }
public string ProductName { get; set; } = string.Empty;
public Guid? OrderId { get; set; }
public string CategoryName { get; set; } = string.Empty;
public decimal? Value { get; set; }
public int? Quantity { get; set; }
public string Platform { get; set; } = "Telegram";
public string DeviceType { get; set; } = string.Empty;
public string Location { get; set; } = string.Empty;
public DateTime Timestamp { get; set; }
public string Metadata { get; set; } = "{}";
}
public class CreateBotActivityDto
{
[Required]
public Guid BotId { get; set; }
[Required]
[StringLength(256)]
public string SessionIdentifier { get; set; } = string.Empty;
[StringLength(100)]
public string UserDisplayName { get; set; } = string.Empty;
[Required]
[StringLength(50)]
public string ActivityType { get; set; } = string.Empty;
[Required]
[StringLength(500)]
public string ActivityDescription { get; set; } = string.Empty;
public Guid? ProductId { get; set; }
[StringLength(200)]
public string ProductName { get; set; } = string.Empty;
public Guid? OrderId { get; set; }
[StringLength(100)]
public string CategoryName { get; set; } = string.Empty;
public decimal? Value { get; set; }
public int? Quantity { get; set; }
[StringLength(100)]
public string Platform { get; set; } = "Telegram";
[StringLength(50)]
public string DeviceType { get; set; } = string.Empty;
[StringLength(100)]
public string Location { get; set; } = string.Empty;
public string Metadata { get; set; } = "{}";
}
public class LiveActivitySummaryDto
{
public int ActiveUsers { get; set; }
public int TotalActivitiesLast5Min { get; set; }
public int ProductViewsLast5Min { get; set; }
public int CartsActiveNow { get; set; }
public decimal TotalValueInCartsNow { get; set; }
public List<string> ActiveUserNames { get; set; } = new();
public List<BotActivityDto> RecentActivities { get; set; } = new();
}

View File

@@ -50,9 +50,10 @@ public class OrderItemDto
{
public Guid Id { get; set; }
public Guid ProductId { get; set; }
public Guid? ProductVariationId { get; set; }
public Guid? ProductMultiBuyId { get; set; }
public string ProductName { get; set; } = string.Empty;
public string? ProductVariationName { get; set; }
public string? ProductMultiBuyName { get; set; }
public string? SelectedVariant { get; set; }
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public decimal TotalPrice { get; set; }
@@ -94,7 +95,9 @@ public class CreateOrderItemDto
[Required]
public Guid ProductId { get; set; }
public Guid? ProductVariationId { get; set; } // Optional: if specified, use variation pricing
public Guid? ProductMultiBuyId { get; set; } // Optional: if specified, use multi-buy pricing
public string? SelectedVariant { get; set; } // Optional: variant choice (color/flavor)
[Range(1, int.MaxValue)]
public int Quantity { get; set; }

View File

@@ -18,7 +18,8 @@ public class ProductDto
public DateTime UpdatedAt { get; set; }
public bool IsActive { get; set; }
public List<ProductPhotoDto> Photos { get; set; } = new();
public List<ProductVariationDto> Variations { get; set; } = new();
public List<ProductMultiBuyDto> MultiBuys { get; set; } = new();
public List<ProductVariantDto> Variants { get; set; } = new();
}
public class ProductPhotoDto
@@ -91,7 +92,7 @@ public class CreateProductPhotoDto
public int DisplayOrder { get; set; }
}
public class ProductVariationDto
public class ProductMultiBuyDto
{
public Guid Id { get; set; }
public Guid ProductId { get; set; }
@@ -106,7 +107,20 @@ public class ProductVariationDto
public DateTime UpdatedAt { get; set; }
}
public class CreateProductVariationDto
public class ProductVariantDto
{
public Guid Id { get; set; }
public Guid ProductId { get; set; }
public string Name { get; set; } = string.Empty;
public string VariantType { get; set; } = "Standard";
public int SortOrder { get; set; }
public int StockLevel { get; set; }
public bool IsActive { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
public class CreateProductMultiBuyDto
{
[Required]
public Guid ProductId { get; set; }
@@ -129,7 +143,26 @@ public class CreateProductVariationDto
public int SortOrder { get; set; }
}
public class UpdateProductVariationDto
public class CreateProductVariantDto
{
[Required]
public Guid ProductId { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; } = string.Empty;
[StringLength(50)]
public string VariantType { get; set; } = "Standard";
[Range(0, int.MaxValue)]
public int SortOrder { get; set; }
[Range(0, int.MaxValue)]
public int StockLevel { get; set; } = 0;
}
public class UpdateProductMultiBuyDto
{
[StringLength(100)]
public string? Name { get; set; }
@@ -145,5 +178,22 @@ public class UpdateProductVariationDto
[Range(0, int.MaxValue)]
public int? SortOrder { get; set; }
public bool? IsActive { get; set; }
}
public class UpdateProductVariantDto
{
[StringLength(100)]
public string? Name { get; set; }
[StringLength(50)]
public string? VariantType { get; set; }
[Range(0, int.MaxValue)]
public int? SortOrder { get; set; }
[Range(0, int.MaxValue)]
public int? StockLevel { get; set; }
public bool? IsActive { get; set; }
}