Ejemplo n.º 1
0
    /// <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
        Activity activity = new ActivityProductRemovedFromShoppingCart(ShoppingCartItemInfoObject, ResHelper.LocalizeString(ShoppingCartItemInfoObject.SKU.SKUName), ContactID, AnalyticsContext.ActivityEnvironmentVariables);

        activity.Log();

        // Recalculate shopping cart
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

        // Raise the change event for all subscribed web parts
        ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Removing Shopping Cart and cart items by cart id
 /// </summary>
 /// <param name="shoppingCartID"></param>
 private void RemovingProductFromShoppingCart(SKUInfo product, int shoppingCartID)
 {
     try
     {
         if (!DataHelper.DataSourceIsEmpty(product))
         {
             ShoppingCartItemInfo item = null;
             ShoppingCartInfo     cart = ShoppingCartInfoProvider.GetShoppingCartInfo(shoppingCartID);
             cart.User = CurrentUser;
             item      = cart.CartItems.Where(g => g.SKUID == product.SKUID).FirstOrDefault();
             if (!DataHelper.DataSourceIsEmpty(item))
             {
                 ShoppingCartInfoProvider.RemoveShoppingCartItem(cart, item.CartItemID);
                 ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(item);
                 if (cart.CartItems.Count == 0)
                 {
                     ShoppingCartInfoProvider.DeleteShoppingCartInfo(shoppingCartID);
                 }
                 cart.InvalidateCalculations();
             }
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("CustomerCartOperations.ascx.cs", "RemovingProductFromShoppingCart()", ex);
     }
 }
Ejemplo n.º 3
0
    /// <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);
    }
        public void RemoveCartItem(int id)
        {
            // Method approach inspired by \CMS\CMSModules\Ecommerce\Controls\Checkout\CartItemRemove.ascx.cs

            var cart = ECommerceContext.CurrentShoppingCart;
            var item = cart.CartItems.FirstOrDefault(i => i.CartItemID == id);

            if (item == null)
            {
                return;
            }

            // Delete all the children from the database if available
            foreach (ShoppingCartItemInfo scii in cart.CartItems)
            {
                if ((scii.CartItemBundleGUID == item.CartItemGUID) || (scii.CartItemParentGUID == item.CartItemGUID))
                {
                    ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii);
                }
            }

            // Deletes the CartItem from the database
            ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(item.CartItemGUID);
            // Delete the CartItem form the shopping cart object (session)
            ShoppingCartInfoProvider.RemoveShoppingCartItem(cart, item.CartItemGUID);

            // Recalculate shopping cart
            ShoppingCartInfoProvider.EvaluateShoppingCart(cart);
        }
 /// <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);
     }
 }
    /// <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 the children from the database if available
                foreach (var scii in ShoppingCart.CartItems.Where(scii => 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);
            }
            else
            {
                // Check if the current item has children, if yes, update the product option unit count
                foreach (var scii in ShoppingCart.CartItems.Where(s => s.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID))
                {
                    scii.CartItemUnits = count;
                    SaveCartItem(scii);
                }
                // Update units of child bundle items
                foreach (var bundleItem in ShoppingCartItemInfoObject.BundleItems)
                {
                    bundleItem.CartItemUnits = count;
                    SaveCartItem(bundleItem);
                }

                ShoppingCartItemInfoObject.CartItemUnits = count;
                SaveCartItem(ShoppingCartItemInfoObject);
            }

            // Invalidate the shopping cart so it is recalculated with the correct values
            ShoppingCart.InvalidateCalculations();
        }

        // Raise the change event for all subscribed web parts
        ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED);
    }
Ejemplo n.º 7
0
    /// <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);
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Removes an item from the shopping cart. Also deletes the cart item from the database.
        /// </summary>
        /// <remarks>
        /// If the cart item has already been removed and does not exist in the cart, no activity is logged.
        /// </remarks>
        /// <param name="itemId">ID of the shopping cart item.</param>
        public void RemoveItem(int itemId)
        {
            var item = Items.FirstOrDefault(i => i.ID == itemId);

            if (item == null)
            {
                return;
            }

            var originalItem = item.OriginalCartItem;

            ShoppingCartInfoProvider.RemoveShoppingCartItem(OriginalCart, originalItem.CartItemID);

            mActivityLogger?.LogProductRemovedFromShoppingCartActivity(originalItem.SKU, originalItem.CartItemUnits);
            ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(originalItem);

            mItems = null;
        }
 /// <summary>
 /// Removes the current cart item and the associated product options from the shopping cart.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void linkRemoveItem_Click(object sender, EventArgs e)
 {
     try
     {
         RepeaterItem item = (sender as LinkButton).Parent as RepeaterItem;
         int cartItemID = int.Parse((item.FindControl("lblCartItemID") as Label).Text);
         ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(cartItemID);
         ShoppingCartInfoProvider.RemoveShoppingCartItem(Cart, cartItemID);
         if (Cart.CartItems.Count == 0)
         {
             ShoppingCartInfoProvider.DeleteShoppingCartInfo(Cart.ShoppingCartID);
         }
         ShoppingCartInfoProvider.EvaluateShoppingCart(Cart);
         ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED);
         Response.Cookies["status"].Value = QueryStringStatus.Deleted;
         Response.Cookies["status"].HttpOnly = false;
         URLHelper.Redirect(Request.RawUrl);
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_RemoveItemFromCart", "Remove", ex.Message);
     }
 }
    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;
        }
    }