public override ActionResult Index()
        {
            AssertProductsLoaded();
            SetPageTitleSimple();
            var sc = WebSessionGet <ShoppingCartViewModel>(WebSession.ShoppingCartSlot) ??
                     ShoppingCartViewModelBuilder.GetShoppingCartViewModelAsync().Result;
            var errorMessages = new List <string>();

            if (!String.IsNullOrEmpty(Request.QueryString[ParamScsErrorCode]))
            {
                errorMessages.Add(GetErrorForScsErrorCode(Request.QueryString[ParamScsErrorCode]));
            }
            if (errorMessages.Any())
            {
                sc.ErrorMessages = errorMessages.ToArray();
            }

            WebSessionSet(WebSession.ShoppingCartSlot, sc);
            SetPageInfo(sc, "Sales.Checkout.ShoppingCart");
            return(View("PageTemplates/Default"));
        }
        public override ActionResult Index()
        {
            //todo: figure out if this ought to be cached:
            var mod = WebSessionGet <ShoppingCartViewModel>(WebSession.ShoppingCartSlot) ??
                      _shoppingCartViewModelBuilder.GetShoppingCartViewModelAsync().Result;

            if (mod == null)
            {
                mod = new ShoppingCartViewModel
                {
                    Count               = 1,
                    Discount            = 1.0m,
                    ShippingAndHandling = 1.0m,
                    ShippingCode        = "dummy",
                    ShippingMethods     = new ShippingMethod[0],
                    SubTotal            = 2.0m,
                    Tax   = 3.0m,
                    Total = 4.0m,
                    Cart  = new Cart
                    {
                        LineItems = new LineItems
                        {
                            LineItem = new []
                            {
                                new LineItem
                                {
                                    Product = new Product
                                    {
                                        Name = "bad",
                                    },
                                    Quantity = 1
                                }
                            }
                        }
                    },
                    IsShoppingCartLocked = false,
                };
            }
            return(PartialView("Index", mod));
        }
示例#3
0
//        [ValidateAntiForgeryToken]
        public ActionResult AddProduct(AddProductModel addProduct)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    int quantity;
                    if (String.IsNullOrEmpty(addProduct.Quantity) || !int.TryParse(addProduct.Quantity, out quantity))
                    {
                        quantity = 1;
                    }
                    int offerId;
                    if (String.IsNullOrEmpty(addProduct.OfferId) || !int.TryParse(addProduct.OfferId, out offerId))
                    {
                        offerId = 0;
                    }
                    var cart = _cartApi.AddProductToCartAsync(Convert.ToInt32(addProduct.ProductId), quantity, offerId).Result;
                    WebSession.Current.SetPersistentProperty(WebSession.ShoppingCartCount, cart.TotalItemsInCart.ToString(CultureInfo.InvariantCulture));
                    return(PartialView("ShoppingCart", _shoppingCartViewModelBuilder.GetShoppingCartViewModelAsync().Result));
                }
                catch (ShopperApiException exc)
                {
                    var model = _shoppingCartViewModelBuilder.GetShoppingCartViewModelAsync().Result;
                    model.ErrorMessages = new[] { exc.ShopperApiError.Description };
                    return(PartialView("ShoppingCart", model));
                }
                catch (Exception)
                {
                    var model = _shoppingCartViewModelBuilder.GetShoppingCartViewModelAsync().Result;
                    model.ErrorMessages = new[] { Res.ShoppingCart_UpdateLineItemFailed };
                    return(PartialView("ShoppingCart", model));
                }
            }
            var vm = _shoppingCartViewModelBuilder.GetShoppingCartViewModelAsync().Result;

            vm.ErrorMessages = InternalGetErrorMessages(ModelState).ToArray();
            return(PartialView("ShoppingCart", vm));
        }