/// <summary> /// Updates the unit count for the current cart item and it's children. /// </summary> public void Update(object sender, EventArgs e) { // Disable update operation for ReadOnly mode if (ReadOnly) { return; } if ((ShoppingCartItemInfoObject != null) && !ShoppingCartItemInfoObject.IsProductOption) { var count = ValidationHelper.GetInteger(unitCountFormControl.Value, -1); // Do nothing (leave old value) for invalid/same input if ((count < 0) || (count == ShoppingCartItemInfoObject.CartItemUnits)) { return; } if (count == 0) { // Delete all item options if available foreach (var option in ShoppingCart.CartItems.Where(scii => scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID)) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(option); } // Delete all bundle items if available foreach (var bundleItem in ShoppingCartItemInfoObject.BundleItems) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(bundleItem); } // Deletes the CartItem from the database ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID); // Delete the CartItem form the shopping cart object (session) ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, ShoppingCartItemInfoObject.CartItemGUID); } else { ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(ShoppingCartItemInfoObject, count); } // Invalidate the shopping cart so it is recalculated with the correct values 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> /// Updates product units in the shopping cart and saves the item change into the database. /// </summary> /// <param name="itemId">ID of the shopping cart item.</param> /// <param name="quantity">New number of the product units.</param> public void UpdateQuantity(int itemId, int quantity) { var item = Items.FirstOrDefault(i => i.ID == itemId); if (item == null) { return; } if (quantity == 0) { RemoveItem(item.ID); return; } ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(item.OriginalCartItem, quantity); mItems = null; }
/// <summary> /// Updating the unit count of shopping cart Item /// </summary> private void Updatingtheunitcountofcartitem(SKUInfo product, int shoppinCartID, int unitCount, int customerAddressID, double skuPrice) { try { var customerAddress = AddressInfoProvider.GetAddressInfo(customerAddressID); if (!DataHelper.DataSourceIsEmpty(product)) { ShoppingCartItemInfo item = null; ShoppingCartInfo cart = ShoppingCartInfoProvider.GetShoppingCartInfo(shoppinCartID); cart.User = CurrentUser; cart.ShoppingCartShippingAddress = customerAddress; if (cart.ShoppingCartCurrencyID <= 0) { cart.ShoppingCartCurrencyID = CurrencyInfoProvider.GetMainCurrency(CurrentSite.SiteID).CurrencyID; cart.Update(); } var campaingnID = ValidationHelper.GetInteger(cart.GetValue("ShoppingCartCampaignID"), default(int)); var programID = ValidationHelper.GetInteger(cart.GetValue("ShoppingCartProgramID"), default(int)); item = cart.CartItems.Where(g => g.SKUID == product.SKUID).FirstOrDefault(); if (!DataHelper.DataSourceIsEmpty(item)) { item.CartItemPrice = skuPrice; ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(item, unitCount); cart.InvalidateCalculations(); } else { ShoppingCartItemParameters parameters = new ShoppingCartItemParameters(product.SKUID, unitCount); parameters.CustomParameters.Add("CartItemCustomerID", customerAddressID); ShoppingCartItemInfo cartItem = cart.SetShoppingCartItem(parameters); cartItem.SetValue("CartItemPrice", skuPrice); cartItem.SetValue("CartItemDistributorID", customerAddressID); cartItem.SetValue("CartItemCampaignID", cartItem.SetValue("CartItemCampaignID", campaingnID)); cartItem.SetValue("CartItemProgramID", programID); ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem); } } } catch (Exception ex) { EventLogProvider.LogException("CustomerCartOperations.ascx.cs", "Updatingtheunitcountofcartitem()", ex); } }
private void UpdateCartItemQuantity(ShoppingCartItemInfo item, int quantity) { var cart = ECommerceContext.CurrentShoppingCart; var productType = item.GetStringValue("ProductType", string.Empty); if (!productType.Contains(ProductTypes.InventoryProduct) && !productType.Contains(ProductTypes.POD) && !productType.Contains(ProductTypes.StaticProduct)) { throw new Exception(ResHelper.GetString("Kadena.Product.QuantityForTypeError", LocalizationContext.CurrentCulture.CultureCode)); } if (productType.Contains(ProductTypes.InventoryProduct) && quantity > item.SKU.SKUAvailableItems) { throw new ArgumentOutOfRangeException(string.Format( ResHelper.GetString("Kadena.Product.SetQuantityForItemError", LocalizationContext.CurrentCulture.CultureCode), quantity, item.CartItemID)); } var documentId = item.GetIntegerValue("ProductPageID", 0); var ranges = dynamicPrices.GetDynamicPricingRanges(documentId); if ((ranges?.Count() ?? 0) > 0) { var price = dynamicPrices.GetDynamicPrice(quantity, ranges); if (price != 0.0m) { item.CartItemPrice = (double)price; ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(item, quantity); } else { throw new Exception(ResHelper.GetString("Kadena.Product.QuantityOutOfRange", LocalizationContext.CurrentCulture.CultureCode)); } } else { ShoppingCartItemInfoProvider.UpdateShoppingCartItemUnits(item, quantity); } cart.InvalidateCalculations(); ShoppingCartInfoProvider.EvaluateShoppingCart(cart); }
protected void btnUpdate_Click(object sender, EventArgs e) { if (ShoppingCart != null) { // Do not update order if it is already paid if (OrderIsPaid) { return; } if (selectCurrency.SelectedID > 0) { ShoppingCart.ShoppingCartCurrencyID = selectCurrency.SelectedID; } // 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 var cartItem = ShoppingCartInfoProvider.GetShoppingCartItem(ShoppingCart, 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 ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, cartItemGuid); if (!ShoppingCartControl.IsInternalOrder) { // Log activity if (!cartItem.IsProductOption && !cartItem.IsBundleItem) { var logger = Service.Resolve <IEcommerceActivityLogger>(); logger.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); } } } } } var couponCode = txtCoupon.Text.Trim(); if (!string.IsNullOrEmpty(couponCode)) { if (!ShoppingCart.AddCouponCode(couponCode)) { // Discount coupon is not valid lblError.Text = GetString("ecommerce.error.couponcodeisnotvalid"); } else { txtCoupon.Text = string.Empty; } } ShoppingCart.Evaluate(); ReloadData(); // Inventory should be checked checkInventory = true; } }
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; } }