Fix: HandleConfirmVariant now passes variant ID instead of null

Critical fix for £0 order bug:
- When users select a variant and click 'Add to Basket', the confirmvar: callback triggers HandleConfirmVariant
- This method was passing variantId: null to AddItem(), causing cart items to have no variant and price £0
- Now looks up selected variant by name, extracts its ID, and passes it to cart
- Added logging to track which variant is being used
- Also includes CSV variant conversion utility and sample fixed import file
This commit is contained in:
2025-10-08 19:54:08 +01:00
parent 5f26a96ae8
commit 91000035f5
3 changed files with 128 additions and 2 deletions

View File

@@ -1753,8 +1753,23 @@ namespace TeleBot.Handlers
var product = await _shopService.GetProductAsync(productId.Value);
if (product == null) return;
// Add to cart with selected variants
var cartItem = session.Cart.AddItem(product, quantity.Value, multiBuyId, variantId: null, selectedVariants);
// Find the variant by name to get its ID and price
Guid? variantId = null;
if (selectedVariants.Any() && product.Variants?.Any() == true)
{
// Use the first selected variant (for single-type products)
var variantName = selectedVariants.First();
var variant = product.Variants.FirstOrDefault(v => v.Name == variantName);
if (variant != null)
{
variantId = variant.Id;
_logger.LogInformation("HandleConfirmVariant: Using variant {Name} (ID: {Id}) at £{Price}",
variant.Name, variant.Id, variant.Price ?? product.Price);
}
}
// Add to cart with selected variant ID
var cartItem = session.Cart.AddItem(product, quantity.Value, multiBuyId, variantId, selectedVariants);
// Send new message with post-add prompt
await bot.SendTextMessageAsync(