Esempio n. 1
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;
        }
        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));
        }
Esempio n. 3
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);
     }
 }
    private void SaveCartItem(ShoppingCartItemInfo scii)
    {
        // Set new cart
        if (ShoppingCart.ShoppingCartID == 0)
        {
            ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);
        }

        ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(scii);
    }
Esempio n. 5
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);
            }
        }
    }
Esempio n. 6
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);
     }
 }
Esempio n. 7
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);
            }
        }
    /// <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);
        }
    }
    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();
                }
            }
        }
    }
    /// <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);
                }
            }
        }
    }
    /// <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;
        }
    }
    /// <summary>
    /// Adds product to the shopping cart.
    /// </summary>
    private void AddProductToShoppingCart()
    {
        SKUID = hdnSKUID.Value.ToInteger(0);

        // Validate input data
        if (!IsValid() || (SKU == null))
        {
            // Do not process
            return;
        }

        // Try to redirect before any currently selected variant checks (selector in listings issue)
        if (RedirectToDetailsEnabled)
        {
            if (!ShowProductOptions)
            {
                // Does product have some enabled product option categories?
                bool hasOptions = !DataHelper.DataSourceIsEmpty(OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, true));

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

        if (SKU.HasVariants)
        {
            // Check if configured variant is available
            if ((SelectedVariant == null) || !SelectedVariant.Variant.SKUEnabled)
            {
                ScriptHelper.RegisterStartupScript(Page, typeof(string), "ShoppingCartAddItemErrorAlert", ScriptHelper.GetAlertScript(GetString("com.cartcontent.nonexistingvariantselected")));
                return;
            }
        }

        // Get cart item parameters
        var cartItemParams = GetShoppingCartItemParameters();

        string error = null;

        // Check if it is possible to add this item to shopping cart
        if (!Service.Resolve <ICartItemChecker>().CheckNewItem(cartItemParams, ShoppingCart))
        {
            error = String.Format(GetString("ecommerce.cartcontent.productdisabled"), SKU.SKUName);
        }

        if (!string.IsNullOrEmpty(error))
        {
            // Show error message and cancel adding the product to shopping cart
            ScriptHelper.RegisterStartupScript(Page, typeof(string), "ShoppingCartAddItemErrorAlert", ScriptHelper.GetAlertScript(error));
            return;
        }

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

        OnAddToShoppingCart?.Invoke(this, eventArgs);

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

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

        if (ShoppingCart != null)
        {
            // Shopping cart is not saved yet
            if (ShoppingCart.ShoppingCartID == 0)
            {
                ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);
            }

            // Add item to shopping cart
            var addedItem = ShoppingCartInfoProvider.SetShoppingCartItem(ShoppingCart, cartItemParams);

            if (addedItem != null)
            {
                addedItem.CartItemAutoAddedUnits = 0;

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

                // Update product options and bundle items in database
                addedItem.ProductOptions.ForEach(ShoppingCartItemInfoProvider.SetShoppingCartItemInfo);
                addedItem.BundleItems.ForEach(ShoppingCartItemInfoProvider.SetShoppingCartItemInfo);

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

                // Recalculate shopping cart
                ShoppingCart.Evaluate();

                // Log activity before possible redirect to shopping cart
                LogProductAddedToSCActivity(addedItem);

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

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

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

                    // Check inventory
                    ShoppingCartCheckResult checkResult = ShoppingCartInfoProvider.CheckShoppingCart(ShoppingCart);
                    string checkInventoryMessage        = checkResult.GetFormattedMessage();

                    // Get product added message
                    string message = String.Format(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(Page, typeof(string), "ShoppingCartItemAddedHandler", "if (typeof ShoppingCartItemAddedHandler == 'function') { ShoppingCartItemAddedHandler(" + ScriptHelper.GetString(message) + "); }", true);
                }
            }
        }
    }