Beispiel #1
0
        public ActionResult Index(BasketRenderingViewModel model)
        {
            var cartServiceProvider = new CartServiceProvider();
            var cart = GetCart();

            foreach (var orderLine in model.OrderLines)
            {
                var newQuantity = orderLine.Quantity;

                if (model.RemoveOrderlineId == orderLine.OrderLineId)
                {
                    newQuantity = 0;
                }

                var bmw = cart.Lines.First(i => i.Product.ProductId == orderLine.Sku);

                bmw.Quantity = (uint)newQuantity;

                if (newQuantity > 0)
                {
                    var updateCartLinesRequest = new UpdateCartLinesRequest(cart, new Collection <CartLine> {
                        bmw
                    });
                    cartServiceProvider.UpdateCartLines(updateCartLinesRequest);
                }
                else
                {
                    var request = new RemoveCartLinesRequest(cart, cart.Lines.Where(l => l.Product.ProductId == bmw.Product.ProductId).ToArray());
                    cartServiceProvider.RemoveCartLines(request);
                }
            }

            return(Redirect("/Cart"));
        }
        public ActionResult Rendering()
        {
            var cart        = GetCart();
            var basketModel = new BasketRenderingViewModel();

            var currency = new Currency()
            {
                ISOCode = cart.CurrencyCode
            };

            foreach (var cartLine in cart.Lines)
            {
                var orderLineViewModel = new BasketRenderingViewModel.OrderlineViewModel();

                orderLineViewModel.Quantity    = (int)cartLine.Quantity;
                orderLineViewModel.ProductName = cartLine.Product.ProductName;
                orderLineViewModel.Sku         = cartLine.Product.ProductId;
                if (cartLine.GetPropertyValue("VariantSku") != null)
                {
                    orderLineViewModel.VariantSku = cartLine.GetPropertyValue("VariantSku").ToString();
                }
                orderLineViewModel.Total    = new Money(cartLine.Total.Amount, currency.ISOCode).ToString();
                orderLineViewModel.Discount = new Money(cartLine.Adjustments.Sum(x => x.Amount), currency.ISOCode).Value;
                if (cartLine.Total.TaxTotal != null)
                {
                    orderLineViewModel.Tax = new Money(cartLine.Total.TaxTotal.Amount, currency.ISOCode).ToString();
                }
                orderLineViewModel.Price      = new Money(cartLine.Product.Price.Amount, currency.ISOCode).ToString();
                orderLineViewModel.ProductUrl = _urlService.GetUrl(_catalogContext.CurrentCatalog,
                                                                   _catalogLibrary.GetProduct(cartLine.Product.ProductId));
                orderLineViewModel.PriceWithDiscount = new Money((cartLine.Product.Price.Amount - cartLine.Adjustments.Sum(x => x.Amount)), currency.ISOCode).ToString();
                orderLineViewModel.OrderLineId       = Convert.ToInt32(cartLine.ExternalCartLineId);

                basketModel.OrderLines.Add(orderLineViewModel);
            }

            basketModel.OrderTotal    = new Money(cart.Total.Amount, currency.ISOCode).ToString();
            basketModel.DiscountTotal = new Money(cart.Adjustments.Sum(x => x.Amount), currency.ISOCode).ToString();
            if (cart.Total.TaxTotal != null)
            {
                basketModel.TaxTotal = new Money(cart.Total.TaxTotal.Amount, currency.ISOCode).ToString();
            }
            basketModel.SubTotal = new Money((cart.Total.Amount - cart.Total.TaxTotal.Amount), currency.ISOCode).ToString();

            return(View(basketModel));
        }
        public ActionResult Rendering()
        {
            var basketModel = new BasketRenderingViewModel();

            if (!_transactionLibrary.HasBasket())
            {
                return(View(basketModel));
            }

            PurchaseOrder basket = _transactionLibrary.GetBasket();

            foreach (var orderLine in basket.OrderLines)
            {
                var orderLineViewModel = new BasketRenderingViewModel.OrderlineViewModel();

                orderLineViewModel.Quantity    = orderLine.Quantity;
                orderLineViewModel.ProductName = orderLine.ProductName;
                orderLineViewModel.Sku         = orderLine.Sku;
                orderLineViewModel.VariantSku  = orderLine.VariantSku;
                orderLineViewModel.Total       = new Money(orderLine.Total.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
                orderLineViewModel.Discount    = orderLine.Discount;
                orderLineViewModel.Tax         = new Money(orderLine.VAT, basket.BillingCurrency.ISOCode).ToString();
                orderLineViewModel.Price       = new Money(orderLine.Price, basket.BillingCurrency.ISOCode).ToString();
                orderLineViewModel.ProductUrl  = _urlService.GetUrl(_catalogContext.CurrentCatalog,
                                                                    _catalogLibrary.GetProduct(orderLine.Sku));
                orderLineViewModel.PriceWithDiscount = new Money(orderLine.Price - orderLine.UnitDiscount.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
                orderLineViewModel.OrderLineId       = orderLine.OrderLineId;

                basketModel.OrderLines.Add(orderLineViewModel);
            }

            basketModel.OrderTotal    = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            basketModel.DiscountTotal = new Money(basket.DiscountTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            basketModel.TaxTotal      = new Money(basket.TaxTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            basketModel.SubTotal      = new Money(basket.SubTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();

            basketModel.RefreshUrl         = Url.Action("UpdateBasket");
            basketModel.RemoveOrderlineUrl = Url.Action("RemoveOrderline");

            return(View(basketModel));
        }