/// <summary> /// Removes the current cart item and the associated product options from the shopping cart. /// </summary> protected void Remove(object sender, EventArgs e) { // Delete all the children from the database if available foreach (ShoppingCartItemInfo scii in ShoppingCart.CartItems) { if ((scii.CartItemBundleGUID == ShoppingCartItemInfoObject.CartItemGUID) || (scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID)) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii); } } // Deletes the CartItem from the database ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID); // Delete the CartItem form the shopping cart object (session) ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, ShoppingCartItemInfoObject.CartItemGUID); // Log remove item activity mActivityLogger.LogProductRemovedFromShoppingCartActivity(ShoppingCartItemInfoObject.SKU, ShoppingCartItemInfoObject.CartItemUnits, ContactID); // Recalculate shopping cart ShoppingCart.Evaluate(); // Make sure that in-memory changes persist (unsaved address, etc.) ECommerceContext.CurrentShoppingCart = ShoppingCart; // Raise the change event for all subscribed web parts ComponentEvents.RequestEvents.RaiseEvent(this, e, SHOPPING_CART_CHANGED); }
/// <summary> /// Removes the current cart item and the associated product options from the shopping cart. /// </summary> protected void Remove(object sender, EventArgs e) { try { cart = ShoppingCartInfoProvider.GetShoppingCartInfo(CartID); foreach (ShoppingCartItemInfo scii in cart.CartItems) { if ((scii.CartItemBundleGUID == ShoppingCartItemInfoObject.CartItemGUID) || (scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID)) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii); } } ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID); ShoppingCartInfoProvider.RemoveShoppingCartItem(cart, ShoppingCartItemInfoObject.CartItemGUID); if (cart.CartItems.Count == 0) { ShoppingCartInfoProvider.DeleteShoppingCartInfo(cart.ShoppingCartID); } mActivityLogger.LogProductRemovedFromShoppingCartActivity(ShoppingCartItemInfoObject.SKU, ShoppingCartItemInfoObject.CartItemUnits, ContactID); ShoppingCartInfoProvider.EvaluateShoppingCart(cart); ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED); URLHelper.Redirect($"{Request.RawUrl}?status={QueryStringStatus.Deleted}"); } catch (Exception ex) { EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_RemoveItemFromCart", "Remove", ex.Message); } }
protected void btnUpdate_Click1(object sender, EventArgs e) { if (ShoppingCart != null) { // Do not update order if it is already paid if (OrderIsPaid) { return; } ShoppingCart.ShoppingCartCurrencyID = ValidationHelper.GetInteger(selectCurrency.SelectedID, 0); // Skip if method was called by btnAddProduct if (sender != btnAddProduct) { foreach (GridViewRow row in gridData.Rows) { // Get shopping cart item Guid Guid cartItemGuid = ValidationHelper.GetGuid(((Label)row.Cells[1].Controls[1]).Text, Guid.Empty); // Try to find shopping cart item in the list ShoppingCartItemInfo cartItem = ShoppingCart.GetShoppingCartItem(cartItemGuid); if (cartItem != null) { // If product and its product options should be removed if (((CMSCheckBox)row.Cells[4].Controls[1]).Checked && (sender != null)) { // Remove product and its product option from list ShoppingCart.RemoveShoppingCartItem(cartItemGuid); if (!ShoppingCartControl.IsInternalOrder) { // Log activity if (!cartItem.IsProductOption && !cartItem.IsBundleItem) { mActivityLogger.LogProductRemovedFromShoppingCartActivity(cartItem.SKU, cartItem.CartItemUnits, ContactID); } // Delete product from database ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(cartItem); } } // If product units has changed else if (!cartItem.IsProductOption) { // Get number of units int itemUnits = ValidationHelper.GetInteger(((TextBox)(row.Cells[7].Controls[1])).Text.Trim(), 0); if ((itemUnits > 0) && (cartItem.CartItemUnits != itemUnits)) { // Update units of the parent product ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(cartItem, itemUnits); } } } } } CheckDiscountCoupon(); // Recalculate shopping cart ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart); ReloadData(); if ((ShoppingCart.ShoppingCartDiscountCouponID > 0) && (!ShoppingCart.IsDiscountCouponApplied)) { // Discount coupon code is valid but not applied to any product of the shopping cart lblError.Text = GetString("shoppingcart.discountcouponnotapplied"); } // Inventory should be checked checkInventory = true; } }