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:
@@ -11,22 +11,30 @@ namespace TeleBot.Models
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public void AddItem(Guid productId, string productName, decimal price, int quantity = 1, Guid? variationId = null)
|
||||
public void AddItem(Guid productId, string productName, decimal price, int quantity = 1, Guid? multiBuyId = null, string? selectedVariant = null)
|
||||
{
|
||||
var existingItem = Items.FirstOrDefault(i =>
|
||||
i.ProductId == productId && i.VariationId == variationId);
|
||||
i.ProductId == productId && i.MultiBuyId == multiBuyId && i.SelectedVariant == selectedVariant);
|
||||
|
||||
if (existingItem != null)
|
||||
{
|
||||
existingItem.Quantity += quantity;
|
||||
existingItem.UpdateTotalPrice();
|
||||
// For multi-buys, we don't add quantities - each multi-buy is a separate bundle
|
||||
// For regular items, we add the quantities together
|
||||
if (!multiBuyId.HasValue)
|
||||
{
|
||||
existingItem.Quantity += quantity;
|
||||
existingItem.UpdateTotalPrice();
|
||||
}
|
||||
// If it's a multi-buy and already exists, we don't add it again
|
||||
// (user should explicitly add another multi-buy bundle if they want more)
|
||||
}
|
||||
else
|
||||
{
|
||||
var newItem = new CartItem
|
||||
{
|
||||
ProductId = productId,
|
||||
VariationId = variationId,
|
||||
MultiBuyId = multiBuyId,
|
||||
SelectedVariant = selectedVariant,
|
||||
ProductName = productName,
|
||||
UnitPrice = price,
|
||||
Quantity = quantity
|
||||
@@ -87,20 +95,30 @@ namespace TeleBot.Models
|
||||
public class CartItem
|
||||
{
|
||||
public Guid ProductId { get; set; }
|
||||
public Guid? VariationId { get; set; }
|
||||
public Guid? MultiBuyId { get; set; } // For quantity pricing (e.g., 3 for £25)
|
||||
public string? SelectedVariant { get; set; } // For color/flavor selection
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public int Quantity { get; set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
public decimal UnitPrice { get; set; } // For multi-buys, this is the bundle price; for regular items, it's per-unit
|
||||
public decimal TotalPrice { get; set; }
|
||||
|
||||
|
||||
public CartItem()
|
||||
{
|
||||
// Don't calculate total in constructor - wait for properties to be set
|
||||
}
|
||||
|
||||
|
||||
public void UpdateTotalPrice()
|
||||
{
|
||||
TotalPrice = UnitPrice * Quantity;
|
||||
// For multi-buys, UnitPrice is already the total bundle price
|
||||
// For regular items, we need to multiply by quantity
|
||||
if (MultiBuyId.HasValue)
|
||||
{
|
||||
TotalPrice = UnitPrice; // Bundle price, not multiplied
|
||||
}
|
||||
else
|
||||
{
|
||||
TotalPrice = UnitPrice * Quantity; // Regular per-unit pricing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user