Exemple #1
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);
     }
 }
 /// <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>
    /// 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);
    }
 public int GetPreBuyDemandCount(int SKUID)
 {
     return(ShoppingCartItemInfoProvider.GetShoppingCartItems()
            .OnSite(SiteContext.CurrentSiteID)
            .Where(x => x.SKUID.Equals(SKUID))
            .Sum(x => x.CartItemUnits));
 }
        public CartItem AddCartItem(NewCartItem newItem, MailingList mailingList = null)
        {
            var addedAmount = newItem?.Quantity ?? 0;

            if (addedAmount < 1)
            {
                throw new ArgumentException(resources.GetResourceString("Kadena.Product.InsertedAmmountValueIsNotValid"));
            }

            var productDocument = DocumentHelper.GetDocument(newItem.DocumentId, new TreeProvider(MembershipContext.AuthenticatedUser));
            var productType     = productDocument.GetValue("ProductType", string.Empty);
            var isTemplatedType = ProductTypes.IsOfType(productType, ProductTypes.TemplatedProduct);

            var cartItem = ECommerceContext.CurrentShoppingCart.CartItems
                           .FirstOrDefault(i => i.SKUID == productDocument.NodeSKUID && i.GetValue("ChilliEditorTemplateID", Guid.Empty) == newItem.TemplateId);
            var isNew = false;

            if (cartItem == null)
            {
                isNew    = true;
                cartItem = isTemplatedType
                    ? CreateCartItem(productDocument, newItem.TemplateId)
                    : CreateCartItem(productDocument);
            }

            var existingAmountInCart = isNew ? 0 : cartItem.CartItemUnits;

            if (productType.Contains(ProductTypes.InventoryProduct))
            {
                EnsureInventoryAmount(productDocument, addedAmount, existingAmountInCart);
            }

            var isMailingType = ProductTypes.IsOfType(productType, ProductTypes.MailingProduct);

            if (isTemplatedType || isMailingType)
            {
                if (isMailingType)
                {
                    if (mailingList?.AddressCount != addedAmount)
                    {
                        throw new ArgumentException(resources.GetResourceString("Kadena.Product.InsertedAmmountValueIsNotValid"));
                    }
                    SetMailingList(cartItem, mailingList);
                }
                SetAmount(cartItem, addedAmount);
            }
            else
            {
                SetAmount(cartItem, addedAmount + existingAmountInCart);
            }

            SetArtwork(cartItem, productDocument.GetStringValue("ProductArtwork", string.Empty));

            RefreshPrice(cartItem, productDocument);
            SetCustomName(cartItem, newItem.CustomProductName);

            ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);

            return(GetShoppingCartItems().FirstOrDefault(i => i.Id == cartItem.CartItemID));
        }
Exemple #6
0
 /// <summary>
 /// Create Shopping cart with item by customer
 /// </summary>
 /// <param name="customerAddressID"></param>
 /// <param name="txtQty"></param>
 private void CreateShoppingCartByCustomer(SKUInfo product, int customerAddressID, int productQty, double skuPrice)
 {
     try
     {
         var customerAddress = AddressInfoProvider.GetAddressInfo(customerAddressID);
         if (!DataHelper.DataSourceIsEmpty(product))
         {
             ShoppingCartInfo cart = new ShoppingCartInfo();
             cart.ShoppingCartSiteID     = CurrentSite.SiteID;
             cart.ShoppingCartCustomerID = customerAddressID;
             cart.ShoppingCartCurrencyID = CurrencyInfoProvider.GetMainCurrency(CurrentSite.SiteID).CurrencyID;
             cart.SetValue("ShoppingCartCampaignID", ProductCampaignID);
             cart.SetValue("ShoppingCartProgramID", ProductProgramID);
             cart.SetValue("ShoppingCartDistributorID", customerAddressID);
             cart.SetValue("ShoppingCartInventoryType", ProductType);
             cart.User = CurrentUser;
             cart.ShoppingCartShippingAddress  = customerAddress;
             cart.ShoppingCartShippingOptionID = ProductShippingID;
             ShoppingCartInfoProvider.SetShoppingCartInfo(cart);
             ShoppingCartItemParameters parameters = new ShoppingCartItemParameters(product.SKUID, productQty);
             parameters.CustomParameters.Add("CartItemCustomerID", customerAddressID);
             ShoppingCartItemInfo cartItem = cart.SetShoppingCartItem(parameters);
             cartItem.SetValue("CartItemPrice", skuPrice);
             cartItem.SetValue("CartItemDistributorID", customerAddressID);
             cartItem.SetValue("CartItemCampaignID", ProductCampaignID);
             cartItem.SetValue("CartItemProgramID", ProductProgramID);
             ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);
             cart.InvalidateCalculations();
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("CustomerCartOperations.ascx.cs", "CreateShoppingCartByCustomer()", ex);
     }
 }
        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);
        }
Exemple #8
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);
    }
Exemple #9
0
        /// <summary>
        /// Adds an item to the shopping cart and saves the newly created cart into the database. Also saves the shopping cart if it wasn't saved yet.
        /// </summary>
        /// <param name="skuId">ID of the added product's SKU object.</param>
        /// <param name="quantity">Number of added product units.</param>
        public void AddItem(int skuId, int quantity = 1)
        {
            var parameters = new ShoppingCartItemParameters
            {
                SKUID    = skuId,
                Quantity = quantity
            };

            var cartItem = ShoppingCartInfoProvider.SetShoppingCartItem(OriginalCart, parameters);

            if (cartItem == null)
            {
                return;
            }

            if (OriginalCart.ShoppingCartID == 0)
            {
                Save(false);
            }

            ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);

            mActivityLogger?.LogProductAddedToShoppingCartActivity(cartItem.SKU, quantity);

            mItems = null;
        }
    private void SaveCartItem(ShoppingCartItemInfo scii)
    {
        // Set new cart
        if (ShoppingCart.ShoppingCartID == 0)
        {
            ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);
        }

        ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(scii);
    }
    /// <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);
    }
Exemple #12
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);
    }
Exemple #13
0
 /// <summary>
 /// Get all Cusromers / Distributers list based on product ID
 /// </summary>
 /// <param name="productID">Producct skuid</param>
 private void BindCustomersList(int productID)
 {
     try
     {
         List <AddressInfo> myAddressList = GetMyAddressBookList();
         if (myAddressList.Count > 0)
         {
             List <int> shoppingCartIDs = ShoppingCartInfoProvider.GetShoppingCarts()
                                          .WhereIn("ShoppingCartDistributorID", myAddressList.Select(g => g.AddressID).ToList())
                                          .WhereEquals("ShoppingCartInventoryType", InventoryType)
                                          .Select(x => x.ShoppingCartID).ToList();
             List <ShoppingCartItemInfo> cartItems = ShoppingCartItemInfoProvider.GetShoppingCartItems()
                                                     .WhereIn("ShoppingCartID", shoppingCartIDs)
                                                     .WhereEquals("SKUID", productID)
                                                     .ToList();
             gvCustomersCart.DataSource = myAddressList
                                          .Distinct()
                                          .Select(g =>
             {
                 var cartItem = cartItems
                                .Where(k => k.GetValue("CartItemDistributorID", default(int)) == g.AddressID && k.SKUID == productID)
                                .FirstOrDefault();
                 return(new
                 {
                     g.AddressID,
                     g.AddressPersonalName,
                     IsSelected = cartItem?.CartItemUnits > 0,
                     ShoppingCartID = cartItem?.ShoppingCartID ?? default(int),
                     SKUID = cartItem?.SKUID ?? default(int),
                     SKUUnits = cartItem?.CartItemUnits ?? default(int)
                 });
             })
                                          .ToList();
             gvCustomersCart.Columns[1].HeaderText = AddressIDText;
             gvCustomersCart.Columns[2].HeaderText = AddressPersonalNameText;
             gvCustomersCart.DataBind();
         }
         else
         {
             lblError.Text    = ResHelper.GetString("Kadena.AddToCart.DistributorError");
             lblError.Visible = true;
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("CustomerCartOperations.ascx.cs", "BindCustomersList()", ex);
     }
 }
        public string UpdateCartQuantity(Distributor distributorData)
        {
            if (distributorData.ItemQuantity < 1)
            {
                throw new Exception(ResHelper.GetString("KDA.Cart.Update.MinimumQuantityError", LocalizationContext.CurrentCulture.CultureCode));
            }
            var shoppingCartItem = ShoppingCartItemInfoProvider.GetShoppingCartItemInfo(distributorData.CartItemId);

            if (distributorData.InventoryType == 1)
            {
                var shoppingCartIDs   = ShoppingCartInfoProvider.GetShoppingCarts().WhereEquals("ShoppingCartUserID", distributorData.UserID).WhereEquals("ShoppingCartInventoryType", 1).ToList().Select(x => x.ShoppingCartID).ToList();
                var shoppingcartItems = ShoppingCartItemInfoProvider.GetShoppingCartItems().WhereIn("ShoppingCartID", shoppingCartIDs).WhereEquals("SKUID", shoppingCartItem.SKUID).ToList();
                int totalItems        = 0;
                shoppingcartItems.ForEach(cartItem =>
                {
                    if (cartItem != null && cartItem.CartItemID != distributorData.CartItemId)
                    {
                        totalItems += cartItem.CartItemUnits;
                    }
                });
                var sku                  = SKUInfoProvider.GetSKUInfo(shoppingCartItem.SKUID);
                var currentProduct       = DocumentHelper.GetDocuments(campaignClassName).WhereEquals("NodeSKUID", sku.SKUID).Columns("CampaignsProductID").FirstOrDefault();
                var productHasAllocation = currentProduct != null?productProvider.IsProductHasAllocation(currentProduct.GetValue <int>("CampaignsProductID", default(int))) : false;

                var allocatedQuantityItem = GetAllocatedProductQuantityForUser(currentProduct.GetValue <int>("CampaignsProductID", default(int)), distributorData.UserID);
                var allocatedQuantity     = allocatedQuantityItem != null?allocatedQuantityItem.GetValue <int>("Quantity", default(int)) : default(int);

                if (sku.SKUAvailableItems < totalItems + distributorData.ItemQuantity)
                {
                    throw new Exception(ResHelper.GetString("KDA.Cart.Update.InsufficientStockMessage", LocalizationContext.CurrentCulture.CultureCode));
                }
                else if (allocatedQuantity < totalItems + distributorData.ItemQuantity && productHasAllocation)
                {
                    throw new Exception(ResHelper.GetString("Kadena.AddToCart.AllocatedProductQuantityError", LocalizationContext.CurrentCulture.CultureCode));
                }
            }
            if (shoppingCartItem != null)
            {
                shoppingCartItem.CartItemUnits = distributorData.ItemQuantity;
                shoppingCartItem.Update();
                return(ResHelper.GetString("KDA.Cart.Update.Success"));
            }
            else
            {
                throw new Exception(ResHelper.GetString("KDA.Cart.Update.Failure", LocalizationContext.CurrentCulture.CultureCode));
            }
        }
Exemple #15
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;

            OriginalCart.RemoveShoppingCartItem(originalItem.CartItemID);

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

            mItems = null;
        }
Exemple #16
0
        /// <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;
        }
Exemple #17
0
 /// <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);
     }
 }
Exemple #18
0
    /// <summary>
    /// Adds content of order to current shopping cart.
    /// </summary>
    private void AddToCart(int orderId)
    {
        if (!ShowOrderToShoppingCart)
        {
            return;
        }

        // Get order
        OrderInfo order = OrderInfoProvider.GetOrderInfo(orderId);

        if (order != null)
        {
            CustomerInfo customer = CustomerInfoProvider.GetCustomerInfo(order.OrderCustomerID);

            if (customer.CustomerUserID == CurrentUser.UserID)
            {
                // Get current shopping cart
                ShoppingCartInfo cart = ECommerceContext.CurrentShoppingCart;
                // Set new cart
                if (cart.ShoppingCartID == 0)
                {
                    ShoppingCartInfoProvider.SetShoppingCartInfo(cart);
                }

                string cartUrl = ECommerceSettings.ShoppingCartURL(CurrentSite.SiteName);

                // Update shopping cart by items from order
                if (!ShoppingCartInfoProvider.UpdateShoppingCartFromOrder(cart, orderId))
                {
                    cartUrl = URLHelper.AddParameterToUrl(cartUrl, "notallreordered", "1");
                }

                // Update shopping cart items in database
                foreach (ShoppingCartItemInfo item in cart.CartItems)
                {
                    ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(item);
                }

                // Redirect to shopping cart page
                URLHelper.ResponseRedirect(cartUrl);
            }
        }
    }
        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);
        }
Exemple #20
0
        /// <summary>
        /// Saves the shopping cart into the database.
        /// </summary>
        /// <param name="validate">Specifies whether the validation should be performed.</param>
        public void Save(bool validate = true)
        {
            if (validate)
            {
                var result = Validate();
                if (result.CheckFailed)
                {
                    throw new InvalidOperationException();
                }
            }

            SaveCustomer();
            SaveAddresses();

            ShoppingCartInfoProvider.SetShoppingCartInfo(OriginalCart);
            foreach (var item in OriginalCart.CartItems)
            {
                item.ShoppingCart   = OriginalCart;
                item.ShoppingCartID = OriginalCart.ShoppingCartID;
                ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(item);
            }
        }
    protected double GetProductPricettc(object oid, object id)
    {
        int              orderId = Convert.ToInt32(oid);
        double           result  = 0;
        ShoppingCartInfo cart    = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId);

        if (cart != null)
        {
            string where = "SKUID = " + id;

            ShoppingCartItemInfo item = null;

            DataSet items = ShoppingCartItemInfoProvider.GetShoppingCartItems(where, null);
            if (!DataHelper.DataSourceIsEmpty(items))
            {
                item   = new ShoppingCartItemInfo(items.Tables[0].Rows[0]);
                result = item.UnitTotalPrice;
            }
        }

        return(System.Math.Round(result, 2));
    }
 /// <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);
     }
 }
    /// <summary>
    /// Creates a new shopping cart record and corresponding shopping cart items records in the database
    /// as a copy of given shopping cart info.
    /// Currency is set according to the currency of given cart.
    /// If a configuration of cart item is no longer available it is not cloned to new shopping cart.
    /// Correct user id for logged user is _not_ handled in this method, because it does not depend on
    /// abandoned cart's user id. It should be handled according to user's status (logged in/anonymous)
    /// in the browser where the cart is loaded:
    ///  - anonymous cart or user's cart opened in the browser where user is logged in - new cart userId should be set to logged user's id
    ///  - anonymous cart or user's cart opened in the browser where user is _not_ logged in - new cart userId should be empty (anonymous cart)
    /// </summary>
    /// <param name="originalCart">Original cart to clone.</param>
    /// <returns>Created shopping cart info.</returns>
    private ShoppingCartInfo CloneShoppingCartInfo(ShoppingCartInfo originalCart)
    {
        using (new CMSActionContext {
            UpdateTimeStamp = false
        })
        {
            ShoppingCartInfo cartClone = ShoppingCartFactory.CreateCart(CurrentSite.SiteID, originalCart.User);

            cartClone.ShoppingCartCurrencyID = originalCart.ShoppingCartCurrencyID;
            cartClone.ShoppingCartLastUpdate = originalCart.ShoppingCartLastUpdate;
            ShoppingCartInfoProvider.SetShoppingCartInfo(cartClone);

            ShoppingCartInfoProvider.CopyShoppingCartItems(originalCart, cartClone);

            // Set the shopping cart items into the database
            foreach (ShoppingCartItemInfo item in cartClone.CartItems)
            {
                ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(item);
            }

            return(cartClone);
        }
    }
    /// <summary>
    /// On btnUpdate click event.
    /// </summary>
    protected void btnUpdate_Click1(object sender, EventArgs e)
    {
        if (this.ShoppingCartInfoObj != null)
        {
            this.ShoppingCartInfoObj.ShoppingCartCurrencyID = ValidationHelper.GetInteger(this.selectCurrency.CurrencyID, 0);

            // Skip if method was called by btnAddProduct
            if (sender != this.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 = this.ShoppingCartInfoObj.GetShoppingCartItem(cartItemGuid);
                    if (cartItem != null)
                    {
                        // If product and its product options should be removed
                        if (((CheckBox)row.Cells[4].Controls[1]).Checked && (sender != null))
                        {
                            // Remove product and its product option from list
                            this.ShoppingCartInfoObj.RemoveShoppingCartItem(cartItemGuid);

                            if (!this.ShoppingCartControl.IsInternalOrder)
                            {
                                if (CMSContext.ViewMode == ViewModeEnum.LiveSite)
                                {
                                    // Log activity
                                    if (!cartItem.IsProductOption && !cartItem.IsBundleItem)
                                    {
                                        this.ShoppingCartControl.TrackActivityProductRemovedFromShoppingCart(cartItem.SKUID, ResHelper.LocalizeString(cartItem.SKUObj.SKUName), this.ContactID,
                                                                                                             CMSContext.CurrentSiteName, URLHelper.CurrentRelativePath, cartItem.CartItemUnits);
                                    }
                                }

                                // Delete product from database
                                ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(cartItemGuid);
                            }
                        }
                        // If product units has changed
                        else if (!cartItem.IsProductOption)
                        {
                            // Get number of units
                            int itemUnits = ValidationHelper.GetInteger(((TextBox)(row.Cells[6].Controls[1])).Text.Trim(), 0);
                            if ((itemUnits > 0) && (cartItem.CartItemUnits != itemUnits))
                            {
                                // Update units of the parent product
                                cartItem.CartItemUnits = itemUnits;

                                // Update units of the child product options
                                foreach (ShoppingCartItemInfo option in cartItem.ProductOptions)
                                {
                                    option.CartItemUnits = itemUnits;
                                }

                                // Update units of child bundle items
                                foreach (ShoppingCartItemInfo bundleItem in cartItem.BundleItems)
                                {
                                    bundleItem.CartItemUnits = itemUnits;
                                }

                                if (!this.ShoppingCartControl.IsInternalOrder)
                                {
                                    ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);

                                    // Update product options in database
                                    foreach (ShoppingCartItemInfo option in cartItem.ProductOptions)
                                    {
                                        ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            CheckDiscountCoupon();

            ReloadData();

            if ((ShoppingCartInfoObj.ShoppingCartDiscountCouponID > 0) && (!this.ShoppingCartInfoObj.IsDiscountCouponApplied))
            {
                // Discount coupon code is valid but not applied to any product of the shopping cart
                lblError.Text = GetString("ShoppingCart.DiscountCouponNotApplied");
            }

            // Inventory shloud be checked
            this.checkInventory = true;
        }
    }
    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;
        }
    }
 public List <ShoppingCartItemInfo> GetShoppingCartItemsByCartIDs(List <int> shoppingCartIDs)
 {
     return(ShoppingCartItemInfoProvider.GetShoppingCartItems().WhereIn("ShoppingCartID", shoppingCartIDs)
            .ToList());
 }
    protected void RptCartItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.Equals("Remove"))
        {
            var cartItemGuid = new Guid(e.CommandArgument.ToString());
            // Remove product and its product option from list
            this.ShoppingCart.RemoveShoppingCartItem(cartItemGuid);

            if (!this.ShoppingCartControl.IsInternalOrder)
            {
                // Delete product from database
                ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(cartItemGuid);
            }
            ReloadData();
        }
        if (e.CommandName.Equals("Decrease"))
        {
            var cartItemGuid = new Guid(e.CommandArgument.ToString());
            ShoppingCartItemInfo cartItem = ShoppingCart.GetShoppingCartItem(cartItemGuid);
            if (cartItem != null)
            {
                if (cartItem.CartItemUnits - 1 > 0)
                {
                    cartItem.CartItemUnits--;
                    // Update units of child bundle items
                    foreach (ShoppingCartItemInfo bundleItem in cartItem.BundleItems)
                    {
                        bundleItem.CartItemUnits--;
                    }

                    if (!ShoppingCartControl.IsInternalOrder)
                    {
                        ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);

                        // Update product options in database
                        foreach (ShoppingCartItemInfo option in cartItem.ProductOptions)
                        {
                            ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option);
                        }
                    }
                    ReloadData();
                }
            }
        }
        if (e.CommandName.Equals("Increase"))
        {
            var cartItemGuid = new Guid(e.CommandArgument.ToString());
            ShoppingCartItemInfo cartItem = ShoppingCart.GetShoppingCartItem(cartItemGuid);
            if (cartItem != null)
            {
                if (cartItem.CartItemUnits + 1 > 0)
                {
                    cartItem.CartItemUnits++;
                    // Update units of child bundle items
                    foreach (ShoppingCartItemInfo bundleItem in cartItem.BundleItems)
                    {
                        bundleItem.CartItemUnits++;
                    }

                    if (!ShoppingCartControl.IsInternalOrder)
                    {
                        ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);

                        // Update product options in database
                        foreach (ShoppingCartItemInfo option in cartItem.ProductOptions)
                        {
                            ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option);
                        }
                    }
                    ReloadData();
                }
            }
        }
    }
    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;
        }
    }
    /// <summary>
    /// Adds product to the shopping cart.
    /// </summary>
    private void AddProductToShoppingCart()
    {
        // Validate input data
        if (!IsValid() || (this.SKU == null))
        {
            // Do not proces
            return;
        }

        if (this.RedirectToDetailsEnabled)
        {
            if (!this.ShowProductOptions && !this.ShowDonationProperties)
            {
                // Does product have some enabled product option categories?
                bool hasOptions = !DataHelper.DataSourceIsEmpty(OptionCategoryInfoProvider.GetSKUOptionCategories(this.SKUID, true));

                // Is product a customizable donation?
                bool isCustomizableDonation = ((this.SKU != null) &&
                                               (this.SKU.SKUProductType == SKUProductTypeEnum.Donation) &&
                                               (!((this.SKU.SKUPrice == this.SKU.SKUMinPrice) && (this.SKU.SKUPrice == this.SKU.SKUMaxPrice)) || this.SKU.SKUPrivateDonation));

                if (hasOptions || isCustomizableDonation)
                {
                    // Redirect to product details
                    URLHelper.Redirect("~/CMSPages/GetProduct.aspx?productid=" + this.SKUID);
                }
            }
        }

        // Get cart item parameters
        ShoppingCartItemParameters cartItemParams = this.GetShoppingCartItemParameters();

        // Check if it is possible to add this item to shopping cart
        if (!ShoppingCartInfoProvider.CheckNewShoppingCartItems(this.ShoppingCart, cartItemParams))
        {
            // Show error message and cancel adding the product to shopping cart
            string error = String.Format(this.GetString("ecommerce.cartcontent.productdisabled"), this.SKU.SKUName);
            ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "ShoppingCartAddItemErrorAlert", ScriptHelper.GetAlertScript(error));
            return;
        }

        // If donation properties are used and donation properties form is not valid
        if (this.donationProperties.Visible && !String.IsNullOrEmpty(this.donationProperties.Validate()))
        {
            return;
        }

        // Fire on add to shopping cart event
        CancelEventArgs eventArgs = new CancelEventArgs();

        if (this.OnAddToShoppingCart != null)
        {
            this.OnAddToShoppingCart(this, eventArgs);
        }

        // If adding to shopping cart was cancelled
        if (eventArgs.Cancel)
        {
            return;
        }

        // Get cart item parameters in case something changed
        cartItemParams = this.GetShoppingCartItemParameters();

        // Log activity
        LogProductAddedToSCActivity(this.SKUID, this.SKU.SKUName, this.Quantity);

        if (this.ShoppingCart != null)
        {
            bool updateCart = false;

            // Assign current shopping cart to current user
            CurrentUserInfo ui = CMSContext.CurrentUser;
            if (!ui.IsPublic())
            {
                this.ShoppingCart.UserInfoObj = ui;
                updateCart = true;
            }

            // Shopping cart is not saved yet
            if (this.ShoppingCart.ShoppingCartID == 0)
            {
                updateCart = true;
            }

            // Update shopping cart when required
            if (updateCart)
            {
                ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCart);
            }

            // Add item to shopping cart
            ShoppingCartItemInfo addedItem = this.ShoppingCart.SetShoppingCartItem(cartItemParams);

            if (addedItem != null)
            {
                // Update shopping cart item in database
                ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(addedItem);

                // Update product options in database
                foreach (ShoppingCartItemInfo option in addedItem.ProductOptions)
                {
                    ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option);
                }

                // Update bundle items in database
                foreach (ShoppingCartItemInfo bundleItem in addedItem.BundleItems)
                {
                    ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(bundleItem);
                }

                // Track 'Add to shopping cart' conversion
                ECommerceHelper.TrackAddToShoppingCartConversion(addedItem);

                // If user has to be redirected to shopping cart
                if (this.RedirectToShoppingCart)
                {
                    // Set shopping cart referrer
                    SessionHelper.SetValue("ShoppingCartUrlReferrer", URLHelper.CurrentURL);

                    // Ensure shopping cart update
                    SessionHelper.SetValue("checkinventory", true);

                    // Redirect to shopping cart
                    URLHelper.Redirect(this.ShoppingCartUrl);
                }
                else
                {
                    // Localize SKU name
                    string skuName = (addedItem.SKUObj != null) ? ResHelper.LocalizeString(addedItem.SKUObj.SKUName) : "";

                    // Check inventory
                    string checkInventoryMessage = ShoppingCartInfoProvider.CheckShoppingCart(this.ShoppingCart).Replace(";", "\n");

                    // Get prodcut added message
                    string message = String.Format(this.GetString("com.productadded"), skuName);

                    // Add inventory check message
                    if (!String.IsNullOrEmpty(checkInventoryMessage))
                    {
                        message += "\n\n" + checkInventoryMessage;
                    }

                    // Count and show total price with options
                    CalculateTotalPrice();

                    // Register the call of JS handler informing about added product
                    ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "ShoppingCartItemAddedHandler", "if (typeof ShoppingCartItemAddedHandler == 'function') { ShoppingCartItemAddedHandler(" + ScriptHelper.GetString(message) + "); }", true);
                }
            }
        }
    }
    /// <summary>
    /// Sets product in the shopping cart.
    /// </summary>
    /// <param name="itemParams">Shoppping cart item parameters</param>
    protected void AddProducts(ShoppingCartItemParameters itemParams)
    {
        // Get main product info
        int productId = itemParams.SKUID;
        int quantity  = itemParams.Quantity;

        if ((productId > 0) && (quantity > 0))
        {
            // Check product/options combination
            if (ShoppingCartInfoProvider.CheckNewShoppingCartItems(ShoppingCartInfoObj, itemParams))
            {
                // Get requested SKU info object from database
                SKUInfo skuObj = SKUInfoProvider.GetSKUInfo(productId);
                if (skuObj != null)
                {
                    // On the live site
                    if (!ShoppingCartControl.IsInternalOrder)
                    {
                        bool updateCart = false;

                        // Assign current shopping cart to current user
                        CurrentUserInfo ui = CMSContext.CurrentUser;
                        if (!ui.IsPublic())
                        {
                            this.ShoppingCartInfoObj.UserInfoObj = ui;
                            updateCart = true;
                        }

                        // Shopping cart is not saved yet
                        if (ShoppingCartInfoObj.ShoppingCartID == 0)
                        {
                            updateCart = true;
                        }

                        // Update shopping cart when required
                        if (updateCart)
                        {
                            ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCartInfoObj);
                        }

                        // Set item in the shopping cart
                        ShoppingCartItemInfo product = this.ShoppingCartInfoObj.SetShoppingCartItem(itemParams);

                        // Update shopping cart item in database
                        ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(product);

                        // Update product options in database
                        foreach (ShoppingCartItemInfo option in product.ProductOptions)
                        {
                            ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option);
                        }

                        // Update bundle items in database
                        foreach (ShoppingCartItemInfo bundleItem in product.BundleItems)
                        {
                            ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(bundleItem);
                        }

                        // Track add to shopping cart conversion
                        ECommerceHelper.TrackAddToShoppingCartConversion(product);
                    }
                    // In CMSDesk
                    else
                    {
                        // Set item in the shopping cart
                        this.ShoppingCartInfoObj.SetShoppingCartItem(itemParams);
                    }
                }
            }

            // Avoid adding the same product after page refresh
            if (lblError.Text == "")
            {
                string url = URLRewriter.CurrentURL;

                if (!string.IsNullOrEmpty(URLHelper.GetUrlParameter(url, "productid")) ||
                    !string.IsNullOrEmpty(URLHelper.GetUrlParameter(url, "quantity")) ||
                    !string.IsNullOrEmpty(URLHelper.GetUrlParameter(url, "options")))
                {
                    // Remove parameters from URL
                    url = URLHelper.RemoveParameterFromUrl(url, "productid");
                    url = URLHelper.RemoveParameterFromUrl(url, "quantity");
                    url = URLHelper.RemoveParameterFromUrl(url, "options");
                    URLHelper.Redirect(url);
                }
            }
        }
    }