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:
56
LittleShop/Models/BotActivity.cs
Normal file
56
LittleShop/Models/BotActivity.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LittleShop.Models;
|
||||
|
||||
public class BotActivity
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid BotId { get; set; }
|
||||
|
||||
[StringLength(256)]
|
||||
public string SessionIdentifier { get; set; } = string.Empty; // Hashed user ID
|
||||
|
||||
[StringLength(100)]
|
||||
public string UserDisplayName { get; set; } = string.Empty; // e.g., "Merlin", "Anonymous User #123"
|
||||
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
public string ActivityType { get; set; } = string.Empty; // e.g., "ViewProduct", "AddToCart", "Checkout", "Browse"
|
||||
|
||||
[StringLength(500)]
|
||||
public string ActivityDescription { get; set; } = string.Empty; // e.g., "Viewing Red Widget", "Added 3x Blue Gadget to cart"
|
||||
|
||||
public Guid? ProductId { get; set; } // Related product if applicable
|
||||
|
||||
[StringLength(200)]
|
||||
public string ProductName { get; set; } = string.Empty; // Denormalized for performance
|
||||
|
||||
public Guid? OrderId { get; set; } // Related order if applicable
|
||||
|
||||
[StringLength(100)]
|
||||
public string CategoryName { get; set; } = string.Empty; // If browsing categories
|
||||
|
||||
public decimal? Value { get; set; } // Monetary value if applicable (cart total, order amount)
|
||||
|
||||
public int? Quantity { get; set; } // Quantity if applicable
|
||||
|
||||
[StringLength(100)]
|
||||
public string Platform { get; set; } = "Telegram"; // Telegram, Discord, Web, etc.
|
||||
|
||||
[StringLength(50)]
|
||||
public string DeviceType { get; set; } = string.Empty; // Mobile, Desktop, etc.
|
||||
|
||||
[StringLength(100)]
|
||||
public string Location { get; set; } = string.Empty; // Country or region if available
|
||||
|
||||
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public string Metadata { get; set; } = "{}"; // JSON for additional flexible data
|
||||
|
||||
// Navigation properties
|
||||
public virtual Bot Bot { get; set; } = null!;
|
||||
public virtual Product? Product { get; set; }
|
||||
public virtual Order? Order { get; set; }
|
||||
}
|
||||
@@ -12,7 +12,10 @@ public class OrderItem
|
||||
|
||||
public Guid ProductId { get; set; }
|
||||
|
||||
public Guid? ProductVariationId { get; set; } // Nullable for backward compatibility
|
||||
public Guid? ProductMultiBuyId { get; set; } // Nullable for backward compatibility
|
||||
|
||||
[StringLength(100)]
|
||||
public string? SelectedVariant { get; set; } // The variant chosen (e.g., "Red", "Vanilla")
|
||||
|
||||
public int Quantity { get; set; }
|
||||
|
||||
@@ -25,5 +28,5 @@ public class OrderItem
|
||||
// Navigation properties
|
||||
public virtual Order Order { get; set; } = null!;
|
||||
public virtual Product Product { get; set; } = null!;
|
||||
public virtual ProductVariation? ProductVariation { get; set; }
|
||||
public virtual ProductMultiBuy? ProductMultiBuy { get; set; }
|
||||
}
|
||||
@@ -36,7 +36,9 @@ public class Product
|
||||
// Navigation properties
|
||||
public virtual Category Category { get; set; } = null!;
|
||||
public virtual ICollection<ProductPhoto> Photos { get; set; } = new List<ProductPhoto>();
|
||||
public virtual ICollection<ProductVariation> Variations { get; set; } = new List<ProductVariation>();
|
||||
public virtual ICollection<ProductMultiBuy> MultiBuys { get; set; } = new List<ProductMultiBuy>();
|
||||
public virtual ICollection<ProductVariant> Variants { get; set; } = new List<ProductVariant>();
|
||||
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>();
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace LittleShop.Models;
|
||||
|
||||
public class ProductVariation
|
||||
public class ProductMultiBuy
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
@@ -16,7 +16,7 @@ public class ProductVariation
|
||||
|
||||
public string Description { get; set; } = string.Empty; // e.g., "Best value for 3 items"
|
||||
|
||||
public int Quantity { get; set; } // The quantity this variation represents (1, 2, 3, etc.)
|
||||
public int Quantity { get; set; } // The quantity this multi-buy represents (1, 2, 3, etc.)
|
||||
|
||||
[Column(TypeName = "decimal(18,2)")]
|
||||
public decimal Price { get; set; } // The price for this quantity (£10, £19, £25)
|
||||
31
LittleShop/Models/ProductVariant.cs
Normal file
31
LittleShop/Models/ProductVariant.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LittleShop.Models;
|
||||
|
||||
public class ProductVariant
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid ProductId { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100)]
|
||||
public string Name { get; set; } = string.Empty; // e.g., "Red", "Blue", "Vanilla", "Chocolate"
|
||||
|
||||
[StringLength(50)]
|
||||
public string VariantType { get; set; } = "Standard"; // e.g., "Color", "Flavor", "Size", "Standard"
|
||||
|
||||
public int SortOrder { get; set; } = 0; // For controlling display order
|
||||
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
public int StockLevel { get; set; } = 0; // Optional: track stock per variant
|
||||
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
// Navigation properties
|
||||
public virtual Product Product { get; set; } = null!;
|
||||
}
|
||||
Reference in New Issue
Block a user