public ActionResult CreatePayment(PaymentPickerViewModel createPaymentViewModel)
        {
            _transactionLibrary.CreatePayment(createPaymentViewModel.SelectedPaymentMethodId, -1m, false, true);
            _transactionLibrary.ExecuteBasketPipeline();

            return(Redirect("/preview"));
        }
        public ActionResult CreateShipment(ShippingPickerViewModel createShipmentViewModel)
        {
            _transactionLibrary.CreateShipment(createShipmentViewModel.SelectedShippingMethodId, Constants.DefaultShipmentAddressName, true);
            _transactionLibrary.ExecuteBasketPipeline();

            return(Redirect("/payment"));
        }
Esempio n. 3
0
        public ActionResult AddVoucher(string voucher)
        {
            bool success = _marketingLibrary.AddVoucher(voucher);

            _transactionLibrary.ExecuteBasketPipeline();

            return(Json(new { voucher, success }));
        }
        public ActionResult UpdateBasket(BasketUpdateBasket model)
        {
            foreach (var updateOrderline in model.RefreshBasket)
            {
                var newQuantity = updateOrderline.OrderLineQty;
                if (newQuantity <= 0)
                {
                    newQuantity = 0;
                }

                _transactionLibrary.UpdateLineItemByOrderLineId(updateOrderline.OrderLineId, newQuantity);
            }

            _transactionLibrary.ExecuteBasketPipeline();

            var basket = _transactionLibrary.GetBasket();

            BasketUpdateBasketViewModel updatedBasket = new BasketUpdateBasketViewModel();

            foreach (var orderLine in basket.OrderLines)
            {
                var orderLineViewModel = new BasketUpdateOrderline();
                orderLineViewModel.OrderlineId       = orderLine.OrderLineId;
                orderLineViewModel.Quantity          = orderLine.Quantity;
                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.PriceWithDiscount = new Money(orderLine.Price - orderLine.Discount, basket.BillingCurrency.ISOCode).ToString();

                updatedBasket.Orderlines.Add(orderLineViewModel);
            }

            string orderTotal    = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            string discountTotal = new Money(basket.DiscountTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            string taxTotal      = new Money(basket.TaxTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            string subTotal      = new Money(basket.SubTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();

            updatedBasket.OrderTotal    = orderTotal;
            updatedBasket.DiscountTotal = discountTotal;
            updatedBasket.TaxTotal      = taxTotal;
            updatedBasket.SubTotal      = subTotal;


            return(Json(new
            {
                MiniBasketRefresh = _miniBasketService.Refresh(),
                OrderTotal = orderTotal,
                DiscountTotal = discountTotal,
                TaxTotal = taxTotal,
                SubTotal = subTotal,
                OrderLines = updatedBasket.Orderlines
            }));
        }
        public ActionResult Save(AddressSaveViewModel addressRendering)
        {
            if (!addressRendering.IsShippingAddressDifferent)
            {
                this.ModelState.Remove("ShippingAddress.FirstName");
                this.ModelState.Remove("ShippingAddress.LastName");
                this.ModelState.Remove("ShippingAddress.EmailAddress");
                this.ModelState.Remove("ShippingAddress.Line1");
                this.ModelState.Remove("ShippingAddress.PostalCode");
                this.ModelState.Remove("ShippingAddress.City");
            }
            if (!ModelState.IsValid)
            {
                var dictionary = ModelState.ToDictionary(kvp => kvp.Key,
                                                         kvp => kvp.Value.Errors
                                                         .Select(e => e.ErrorMessage).ToArray())
                                 .Where(m => m.Value.Any());

                return(Json(new { modelStateErrors = dictionary }));
            }

            if (addressRendering.IsShippingAddressDifferent)
            {
                EditBillingInformation(addressRendering.BillingAddress);
                EditShippingInformation(addressRendering.ShippingAddress);
            }

            else
            {
                EditBillingInformation(addressRendering.BillingAddress);
                EditShippingInformation(addressRendering.BillingAddress);
            }

            if (Tracker.Current != null)
            {
                Tracker.Current.Session.CustomData["FirstName"] = addressRendering.BillingAddress.FirstName;
            }

            _transactionLibrary.ExecuteBasketPipeline();

            return(Json(new { ShippingUrl = "/shipping" }));
        }