From 1e93008df4e2c4d416880efa6354fa8eab86b8ad Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Mon, 6 Oct 2025 02:44:28 +0100 Subject: [PATCH] Fix: Variant selection now accumulates across types instead of resetting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 { 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 --- TeleBot/TeleBot/Handlers/CallbackHandler.cs | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/TeleBot/TeleBot/Handlers/CallbackHandler.cs b/TeleBot/TeleBot/Handlers/CallbackHandler.cs index 8c0e021..b3be7ab 100644 --- a/TeleBot/TeleBot/Handlers/CallbackHandler.cs +++ b/TeleBot/TeleBot/Handlers/CallbackHandler.cs @@ -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 { variantName }; + // Get existing selections + var selectedVariants = session.TempData.ContainsKey("selected_variants") + ? session.TempData["selected_variants"] as List ?? new List() + : new List(); + + // 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")