public JsonResult AddBundleCartLine(string addToCart_CatalogName, string addToCart_ProductId, string addtocart_relatedvariantids, Decimal quantity) { BaseJsonResult baseJsonResult = this.ModelProvider.GetModel <BaseJsonResult>(); try { string[] relatedVariantIds = addtocart_relatedvariantids.Split(','); if (relatedVariantIds.Any()) { foreach (string relatedVariantId in relatedVariantIds.Where(id => !String.IsNullOrEmpty(id))) { string bundleProductId = relatedVariantId; Decimal bundleProductQuantity = 1; if (relatedVariantId.Contains('&')) { bundleProductId = relatedVariantId.Split('&')[0]; bundleProductQuantity = Decimal.Parse(relatedVariantId.Split('&')[1].Split('=')[1]); } var bundleProduct = _searchManager.GetProduct(bundleProductId.Contains('|') ? bundleProductId.Split('|')[0] : bundleProductId, addToCart_CatalogName); string bundleBaseProductId = bundleProductId; string bundleVariantId = "-1"; if (bundleProduct.HasChildren) { bundleVariantId = bundleProduct.Children[0].Name; } if (bundleProductId.Contains('|')) { bundleBaseProductId = bundleProductId.Split('|')[0]; bundleVariantId = bundleProductId.Split('|')[1]; } baseJsonResult = this.AddToCartRepository.AddLineItemsToCart(this.StorefrontContext, this.VisitorContext, addToCart_CatalogName, bundleBaseProductId, bundleVariantId, bundleProductQuantity); } } Item baseProduct = _searchManager.GetProduct(addToCart_ProductId, addToCart_CatalogName); string variantId = "-1"; if (baseProduct.HasChildren) { variantId = baseProduct.Children[0].Name; } baseJsonResult = this.AddToCartRepository.AddLineItemsToCart(this.StorefrontContext, this.VisitorContext, addToCart_CatalogName, addToCart_ProductId, variantId, quantity); baseJsonResult.Success = true; } catch (Exception ex) { baseJsonResult = this.ModelProvider.GetModel <BaseJsonResult>(); baseJsonResult.SetErrors(nameof(AddCartLine), ex); } return(this.Json(baseJsonResult)); }