public IViewComponentResult Import(QuickOrderProductViewModel[] productsList)
        {
            var returnedMessages = new List <string>();

            ModelState.Clear();

            if (Cart == null)
            {
                _cart = _cartService.LoadOrCreateCart(_cartService.DefaultCartName);
            }

            foreach (var product in productsList)
            {
                if (!product.ProductName.Equals("removed"))
                {
                    var variationReference = _referenceConverter.GetContentLink(product.Sku);
                    var currentQuantity    = GetCurrentItemQuantity(product.Sku);
                    product.Quantity += (int)currentQuantity;
                    var responseMessage = _quickOrderService.ValidateProduct(variationReference, Convert.ToDecimal(product.Quantity), product.Sku);
                    AddToCartQuickOrder(_cart, product, returnedMessages, responseMessage);
                }
            }

            if (returnedMessages.Count == 0)
            {
                returnedMessages.Add("All items were added to cart.");
            }
            TempData["messages"] = returnedMessages;

            var model = new { Message = returnedMessages, TotalItem = Cart.GetAllLineItems().Sum(x => x.Quantity) };

            return(new ContentViewComponentResult(JsonConvert.SerializeObject(model)));
        }
Ejemplo n.º 2
0
        public ActionResult Import(QuickOrderProductViewModel[] productsList)
        {
            var returnedMessages = new List <string>();

            ModelState.Clear();

            if (Cart == null)
            {
                _cart = _cartService.LoadOrCreateCart(_cartService.DefaultCartName);
            }

            foreach (var product in productsList)
            {
                if (!product.ProductName.Equals("removed"))
                {
                    var variationReference = _referenceConverter.GetContentLink(product.Sku);
                    var currentQuantity    = GetCurrentItemQuantity(product.Sku);
                    product.Quantity += (int)currentQuantity;
                    var responseMessage = _quickOrderService.ValidateProduct(variationReference, Convert.ToDecimal(product.Quantity), product.Sku);
                    if (responseMessage.IsNullOrEmpty())
                    {
                        var result = _cartService.AddToCart(Cart, new NamedCarts.RequestParamsToCart {
                            Code = product.Sku, Quantity = 1, Store = "delivery", SelectedStore = ""
                        });
                        if (!result.EntriesAddedToCart)
                        {
                            continue;
                        }
                        _cartService.ChangeCartItem(Cart, 0, product.Sku, product.Quantity, "", "");
                        _orderRepository.Save(Cart);
                    }
                    else
                    {
                        returnedMessages.Add(responseMessage);
                    }
                }
            }
            if (returnedMessages.Count == 0)
            {
                returnedMessages.Add("All items were added to cart.");
            }
            TempData["messages"] = returnedMessages;

            return(Json(new { Message = returnedMessages, TotalItem = Cart.GetAllLineItems().Sum(x => x.Quantity) }));
        }
Ejemplo n.º 3
0
        public ActionResult Import(ProductViewModel[] ProductsList)
        {
            var returnedMessages = new List <string>();

            ModelState.Clear();

            if (Cart == null)
            {
                _cart = _cartService.LoadOrCreateCart(_cartService.DefaultCartName);
            }

            foreach (var product in ProductsList)
            {
                if (!product.ProductName.Equals("removed"))
                {
                    ContentReference variationReference = _referenceConverter.GetContentLink(product.Sku);
                    var currentQuantity = GetCurrentItemQuantity(product.Sku);
                    product.Quantity += (int)currentQuantity;
                    var responseMessage = _quickOrderService.ValidateProduct(variationReference, Convert.ToDecimal(product.Quantity), product.Sku);
                    if (responseMessage.IsNullOrEmpty())
                    {
                        var result = _cartService.AddToCart(Cart, product.Sku, 1, "delivery", "");
                        if (!result.EntriesAddedToCart)
                        {
                            continue;
                        }
                        _cartService.ChangeCartItem(Cart, 0, product.Sku, product.Quantity, "", "");
                        _orderRepository.Save(Cart);
                    }
                    else
                    {
                        returnedMessages.Add(responseMessage);
                    }
                }
            }
            if (returnedMessages.Count == 0)
            {
                returnedMessages.Add("All items were added to cart.");
            }
            TempData["messages"] = returnedMessages;

            var quickOrderPage = GetQuickOrderPage();

            return(Redirect(quickOrderPage?.LinkURL ?? Request.UrlReferrer.AbsoluteUri));
        }
Ejemplo n.º 4
0
        public JsonResult AddVariantsToCart(List <string> variants)
        {
            var returnedMessages = new List <string>();

            ModelState.Clear();

            if (CartWithValidationIssues.Cart == null)
            {
                _cart = new CartWithValidationIssues
                {
                    Cart             = _cartService.LoadOrCreateCart(_cartService.DefaultCartName),
                    ValidationIssues = new Dictionary <ILineItem, List <ValidationIssue> >()
                };
            }

            foreach (var product in variants)
            {
                var sku      = product.Split(';')[0];
                var quantity = Convert.ToInt32(product.Split(';')[1]);

                var variationReference = _referenceConverter.GetContentLink(sku);

                var responseMessage = _quickOrderService.ValidateProduct(variationReference, Convert.ToDecimal(quantity), sku);
                if (responseMessage.IsNullOrEmpty())
                {
                    var result = _cartService.AddToCart(CartWithValidationIssues.Cart,
                                                        new RequestParamsToCart {
                        Code = sku, Quantity = quantity, Store = "delivery", SelectedStore = ""
                    });
                    if (result.EntriesAddedToCart)
                    {
                        _cartService.ChangeCartItem(CartWithValidationIssues.Cart, 0, sku, quantity, "", "");
                        _orderRepository.Save(CartWithValidationIssues.Cart);
                    }
                }
                else
                {
                    returnedMessages.Add(responseMessage);
                }
            }
            Session[Constant.ErrorMessages] = returnedMessages;

            return(Json(returnedMessages, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public JsonResult AddVariantsToOrderPad(List <string> variants)
        {
            var returnedMessages = new List <string>();

            ModelState.Clear();

            if (WishList.Cart == null)
            {
                _wishlist = new CartWithValidationIssues
                {
                    Cart             = _cartService.LoadOrCreateCart(_cartService.DefaultWishListName),
                    ValidationIssues = new Dictionary <ILineItem, List <ValidationIssue> >()
                };
            }

            foreach (var product in variants)
            {
                var sku      = product.Split(';')[0];
                var quantity = Convert.ToInt32(product.Split(';')[1]);

                var variationReference = _referenceConverter.GetContentLink(sku);

                var responseMessage = _quickOrderService.ValidateProduct(variationReference, Convert.ToDecimal(quantity), sku);
                if (string.IsNullOrEmpty(responseMessage))
                {
                    if (_cartService.AddToCart(WishList.Cart, sku, 1, "delivery", "").EntriesAddedToCart)
                    {
                        _orderRepository.Save(WishList.Cart);
                    }
                }
                else
                {
                    returnedMessages.Add(responseMessage);
                }
            }
            Session[Constant.ErrorMessages] = returnedMessages;

            return(Json(returnedMessages, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        public JsonResult AddVariantsToCart(List <string> variants)
        {
            var returnedMessages = new List <string>();

            ModelState.Clear();

            if (Cart == null)
            {
                _cart = _cartService.LoadOrCreateCart(_cartService.DefaultCartName);
            }

            foreach (var product in variants)
            {
                var sku      = product.Split(';')[0];
                var quantity = Convert.ToInt32(product.Split(';')[1]);

                ContentReference variationReference = _referenceConverter.GetContentLink(sku);

                var responseMessage = _quickOrderService.ValidateProduct(variationReference, Convert.ToDecimal(quantity), sku);
                if (responseMessage.IsNullOrEmpty())
                {
                    string warningMessage;
                    if (_cartService.AddToCart(Cart, sku, out warningMessage))
                    {
                        _cartService.ChangeCartItem(Cart, 0, sku, quantity, "", "");
                        _orderRepository.Save(Cart);
                    }
                }
                else
                {
                    returnedMessages.Add(responseMessage);
                }
            }
            Session[Constants.ErrorMesages] = returnedMessages;

            return(Json(returnedMessages, JsonRequestBehavior.AllowGet));
        }