Fix: Variant selection now accumulates across types instead of resetting
Problem:
- Selecting Size then Color would reset Size selection
- Users could never get "Add to Cart" button with multiple variant types
- Each selection created a NEW list, wiping previous choices
Root Cause:
- HandleSetVariant created: new List<string> { variantName }
- This replaced all previous selections instead of accumulating
Fix:
1. Get existing selected variants from session
2. Find the variant type of newly selected variant
3. Remove any previous selection from the SAME type (allow changing choice)
4. Add the new selection
5. Save accumulated list back to session
Example behavior now:
- Select "Red" (Color) → selectedVariants = ["Red"]
- Select "Large" (Size) → selectedVariants = ["Red", "Large"] ✅
- Select "Blue" (Color) → selectedVariants = ["Blue", "Large"] ✅
- Can now confirm when all types selected
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
cb80e0161c
commit
1e93008df4
@ -1430,8 +1430,27 @@ namespace TeleBot.Handlers
|
||||
var product = await _shopService.GetProductAsync(productId.Value);
|
||||
if (product == null) return;
|
||||
|
||||
// For single item, replace selection
|
||||
var selectedVariants = new List<string> { variantName };
|
||||
// Get existing selections
|
||||
var selectedVariants = session.TempData.ContainsKey("selected_variants")
|
||||
? session.TempData["selected_variants"] as List<string> ?? new List<string>()
|
||||
: new List<string>();
|
||||
|
||||
// Find the variant type for the selected variant
|
||||
var selectedVariantObj = product.Variants?.FirstOrDefault(v => v.Name == variantName);
|
||||
if (selectedVariantObj != null)
|
||||
{
|
||||
// Remove any previous selection from the same variant type
|
||||
var variantsOfSameType = product.Variants
|
||||
.Where(v => v.VariantType == selectedVariantObj.VariantType)
|
||||
.Select(v => v.Name)
|
||||
.ToList();
|
||||
|
||||
selectedVariants.RemoveAll(v => variantsOfSameType.Contains(v));
|
||||
|
||||
// Add the new selection
|
||||
selectedVariants.Add(variantName);
|
||||
}
|
||||
|
||||
session.TempData["selected_variants"] = selectedVariants;
|
||||
|
||||
var quantity = session.TempData.ContainsKey("current_quantity")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user