public ActionResult AddItem(int itemSkuId, int itemUnits)
        {
            // Adds the specified number of units of a given product to the current shopping cart
            shoppingService.AddItemToCart(itemSkuId, itemUnits);

            // Displays the shopping cart
            return(RedirectToAction("ShoppingCart"));
        }
Exemplo n.º 2
0
        public ActionResult AddItem(CartItemUpdateModel item)
        {
            if (ModelState.IsValid)
            {
                mShoppingService.AddItemToCart(item.SKUID, item.Units);
            }

            return(RedirectToAction("ShoppingCart"));
        }
        /// <summary>
        /// Fills the shopping cart with generated products of random quantities.
        /// </summary>
        /// <param name="SKUIDs">See <see cref="GetRelevantSKUIDs"/>></param>
        private void FillCart(List <int> SKUIDs)
        {
            for (int i = 0; i < 3; i++)
            {
                int chosenSKUID = new Random().Next(0, SKUIDs.Count - 1);
                int units       = new Random().Next(1, 6);

                var info = shoppingService.AddItemToCart(SKUIDs[chosenSKUID], units);
                Console.WriteLine(info.ToString());
            }
        }
    /// <summary>
    /// Sets product in the shopping cart.
    /// </summary>
    /// <param name="itemParams">Shopping cart item parameters</param>
    protected void AddProducts(ShoppingCartItemParameters itemParams)
    {
        IShoppingService shoppingService = Service.Resolve <IShoppingService>();

        var ui = MembershipContext.AuthenticatedUser;

        if (!ui.IsPublic())
        {
            ShoppingCart.User = ui;
            ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);
        }
        if (!ShoppingCartControl.IsInternalOrder)
        {
            var addedItem = shoppingService.AddItemToCart(itemParams);

            // Track add to shopping cart conversion
            ECommerceHelper.TrackAddToShoppingCartConversion(addedItem);
        }
        else if (Service.Resolve <ICartItemChecker>().CheckNewItem(itemParams, ShoppingCart))
        {
            ShoppingCartInfoProvider.SetShoppingCartItem(ShoppingCart, itemParams);
        }

        // Avoid adding the same product after page refresh
        if (lblError.Text == "")
        {
            string url = RequestContext.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);
            }
        }
    }