/// <summary> /// Handles the ItemCommand event of the UcProductsListView control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param> protected void UcProductsListView_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName != "Delete" || string.IsNullOrEmpty((string)e.CommandArgument)) { return; } ListString listString = new ListString((string)e.CommandArgument); string productCode = listString[0]; ProductLine existingProductLine = this.Cart.ShoppingCartLines.FirstOrDefault(p => p.Product.Code.Equals(productCode)); if (existingProductLine != null) { AnalyticsUtil.ShoppingCartItemRemoved(productCode, existingProductLine.Product.Title, existingProductLine.Quantity); } IShoppingCartManager shoppingCartManager = Sitecore.Ecommerce.Context.Entity.Resolve <IShoppingCartManager>(); shoppingCartManager.RemoveProductLine(productCode); if (this.Cart.ShoppingCartLines.Count == 0) { this.Response.Redirect(LinkManager.GetItemUrl(Sitecore.Context.Item)); } Sitecore.Ecommerce.Context.Entity.SetInstance(this.Cart); this.UpdateTotals(this.Cart); this.UpdateProductLines(this.Cart); }
/// <summary> /// Deletes the product line from shopping cart. /// </summary> /// <param name="productCode">The product code.</param> public static void DeleteProductLineFromShoppingCart(string productCode) { Assert.ArgumentNotNullOrEmpty(productCode, "productCode"); ShoppingCart shoppingCart = Context.Entity.GetInstance <ShoppingCart>(); ShoppingCartLine existingShoppingCartLine = shoppingCart.ShoppingCartLines.FirstOrDefault(p => p.Product.Code.Equals(productCode)); if (existingShoppingCartLine != null) { try { Tracker.StartTracking(); AnalyticsUtil.ShoppingCartItemRemoved(existingShoppingCartLine.Product.Code, existingShoppingCartLine.Product.Title, existingShoppingCartLine.Quantity); } catch (Exception ex) { LogException(ex); } } IShoppingCartManager shoppingCartManager = Context.Entity.Resolve <IShoppingCartManager>(); shoppingCartManager.RemoveProductLine(productCode); }