Esempio n. 1
0
        /// <summary>
        /// Validates if the specified item can be added to the cart
        /// </summary>
        /// <param name="itemSKU">The SKU of the item to be added to the cart</param>
        /// <param name="quant">The desired quantity of the item to be added to the cart</param>
        /// <param name="cartID">The ID of the current cart</param>
        /// <returns>True if the item can be added to the cart</returns>
        public bool ItemCanBeAdded(string itemSKU, int quant, int cartID)
        {
            string[] s_lastInsertedItem     = lastInsertedItem.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            string[] s_lastInsertedQuantity = lastInsertedQuant.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            string[] t_originalCartDetails  = DBOps.GetUserCart(cartID);

            for (int i = 0; i < s_lastInsertedItem.Length; i++)
            {
                if (s_lastInsertedItem[i].Trim() == itemSKU.Trim())
                {
                    int t_quant = Convert.ToInt32(s_lastInsertedQuantity[i]);

                    /// The variables in the cart object get updated before
                    /// this method is called. That is why we check if the
                    /// current quantity will equate to an amount that is
                    /// greater than 99 or any defined limit.
                    if (t_quant > 99 || DBOps.GetProductQuantity(itemSKU) <= 0)
                    {
                        lastInsertedPrice = t_originalCartDetails[1];
                        lastInsertedQuant = t_originalCartDetails[2];
                        totalItemQuantity = Convert.ToInt32(t_originalCartDetails[3]);
                        totalCartPrice    = Convert.ToDecimal(t_originalCartDetails[4]);
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates a specified user's cart with data from another cart
        /// </summary>
        /// <param name="cartID">The ID of the cart that's being used</param>
        /// <param name="user">The E-mail address of the user who's cart to sync with</param>
        public void SyncCart(int cartID, string user)
        {
            string[] oldCartData     = DBOps.GetUserCart(DBOps.GetLatestEntry(DBOps.GetUserID(user)));
            string[] currentCartData = null;

            string[] r_currCartDataItems  = null;
            string[] r_currCartDataPrices = null;
            string[] r_currCartDataQuants = null;
            int      r_currQuant          = -1;
            decimal  r_currPrice          = -1;

            lastInsertedItem  = oldCartData[0];
            lastInsertedPrice = oldCartData[1];
            lastInsertedQuant = oldCartData[2];
            totalItemQuantity = Convert.ToInt32(oldCartData[3]);
            totalCartPrice    = Convert.ToDecimal(oldCartData[4]);

            try
            {
                currentCartData      = DBOps.GetUserCart(cartID);
                r_currCartDataItems  = currentCartData[0].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                r_currCartDataPrices = currentCartData[1].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                r_currCartDataQuants = currentCartData[2].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                r_currQuant          = Convert.ToInt32(currentCartData[3]);
                r_currPrice          = Convert.ToDecimal(currentCartData[4]);

                for (int i = 0; i < r_currCartDataItems.Length; i++)
                {
                    AddItem(r_currCartDataItems[i], Convert.ToDecimal(r_currCartDataPrices[i]), Convert.ToInt32(r_currCartDataQuants[i]));
                }
            }
            catch { }
        }