コード例 #1
0
        public void UpdatePaymentAddress(CheckoutViewModel viewModel)
        {
            var orderSummary     = _orderSummaryViewModelFactory.CreateOrderSummaryViewModel(CartWithValidationIssues.Cart);
            var isMissingPayment = !CartWithValidationIssues.Cart.Forms.SelectMany(x => x.Payments).Any();

            if (isMissingPayment || orderSummary.PaymentTotal != 0)
            {
                if (viewModel.BillingAddressType == 1)
                {
                    if (string.IsNullOrEmpty(viewModel.BillingAddress.AddressId))
                    {
                        ModelState.AddModelError("BillingAddress.AddressId", "Address is required.");
                    }
                }

                if (isMissingPayment)
                {
                    ModelState.AddModelError("SelectedPayment", _localizationService.GetString("/Shared/PaymentRequired"));
                    return;
                }

                if (orderSummary.PaymentTotal != 0)
                {
                    ModelState.AddModelError("PaymentTotal", "PaymentTotal is invalid.");
                    return;
                }
            }

            if (viewModel.BillingAddressType == 1)
            {
                if (string.IsNullOrEmpty(viewModel.BillingAddress.AddressId))
                {
                    ModelState.AddModelError("BillingAddress.AddressId", "Address is required.");
                    return;
                }

                _addressBookService.LoadAddress(viewModel.BillingAddress);
            }
            else if (viewModel.BillingAddressType == 2)
            {
                viewModel.BillingAddress = viewModel.Shipments.FirstOrDefault()?.Address;
                if (viewModel.BillingAddress == null)
                {
                    ModelState.AddModelError("BillingAddress.AddressId", "Shipping address is required.");
                    return;
                }
            }
            else
            {
                var addressName = viewModel.BillingAddress.FirstName + " " + viewModel.BillingAddress.LastName;
                viewModel.BillingAddress.AddressId = null;
                viewModel.BillingAddress.Name      = addressName + " " + DateTime.Now.ToString();
            }

            foreach (var payment in CartWithValidationIssues.Cart.GetFirstForm().Payments)
            {
                payment.BillingAddress = _addressBookService.ConvertToAddress(viewModel.BillingAddress, CartWithValidationIssues.Cart);
            }
        }
コード例 #2
0
ファイル: CartService.cs プロジェクト: khnbb/Quicksilver
        public void RecreateLineItemsBasedOnShipments(ICart cart, IEnumerable <CartItemViewModel> cartItems, IEnumerable <AddressModel> addresses)
        {
            var form  = cart.GetFirstForm();
            var items = cartItems
                        .GroupBy(x => new { x.AddressId, x.Code, x.DisplayName, x.IsGift })
                        .Select(x => new
            {
                Code        = x.Key.Code,
                DisplayName = x.Key.DisplayName,
                AddressId   = x.Key.AddressId,
                Quantity    = x.Count(),
                IsGift      = x.Key.IsGift
            });

            foreach (var shipment in form.Shipments)
            {
                shipment.LineItems.Clear();
            }

            form.Shipments.Clear();

            foreach (var address in addresses)
            {
                var shipment = cart.CreateShipment(_orderGroupFactory);
                form.Shipments.Add(shipment);
                shipment.ShippingAddress = _addressBookService.ConvertToAddress(address, cart);

                foreach (var item in items.Where(x => x.AddressId == address.AddressId))
                {
                    var lineItem = cart.CreateLineItem(item.Code, _orderGroupFactory);
                    lineItem.DisplayName = item.DisplayName;
                    lineItem.IsGift      = item.IsGift;
                    lineItem.Quantity    = item.Quantity;
                    shipment.LineItems.Add(lineItem);
                }
            }

            ValidateCart(cart);
        }
コード例 #3
0
        public ActionResult UpdatePaymentAddress(CheckoutPage currentPage, CheckoutViewModel viewModel)
        {
            var orderSummary     = _orderSummaryViewModelFactory.CreateOrderSummaryViewModel(CartWithValidationIssues.Cart);
            var isMissingPayment = !CartWithValidationIssues.Cart.Forms.SelectMany(x => x.Payments).Any();

            if (isMissingPayment || orderSummary.PaymentTotal != 0)
            {
                var model = CreateCheckoutViewModel(currentPage);
                model.OrderSummary   = orderSummary;
                model.AddressType    = viewModel.AddressType;
                model.BillingAddress = viewModel.BillingAddress;

                if (viewModel.AddressType == 1)
                {
                    if (string.IsNullOrEmpty(viewModel.BillingAddress.AddressId))
                    {
                        ModelState.AddModelError("BillingAddress.AddressId", "Address is required.");
                        model.AddressType = 1;
                    }
                }

                if (isMissingPayment)
                {
                    ModelState.AddModelError("SelectedPayment", _localizationService.GetString("/Shared/PaymentRequired"));
                }

                if (orderSummary.PaymentTotal != 0)
                {
                    ModelState.AddModelError("PaymentTotal", "PaymentTotal is invalid.");
                }

                return(View("BillingInformation", model));
            }

            if (viewModel.AddressType == 1)
            {
                if (string.IsNullOrEmpty(viewModel.BillingAddress.AddressId))
                {
                    ModelState.AddModelError("BillingAddress.AddressId", "Address is required.");
                    var model = CreateCheckoutViewModel(currentPage);
                    model.OrderSummary = orderSummary;
                    model.AddressType  = 1;
                    return(View("BillingInformation", model));
                }

                _addressBookService.LoadAddress(viewModel.BillingAddress);
            }
            else
            {
                var addressName = viewModel.BillingAddress.FirstName + " " + viewModel.BillingAddress.LastName;
                viewModel.BillingAddress.AddressId = null;
                viewModel.BillingAddress.Name      = addressName + " " + DateTime.Now.ToString();
                _addressBookService.Save(viewModel.BillingAddress);
            }

            foreach (var payment in CartWithValidationIssues.Cart.GetFirstForm().Payments)
            {
                payment.BillingAddress = _addressBookService.ConvertToAddress(viewModel.BillingAddress, CartWithValidationIssues.Cart);
            }

            _orderRepository.Save(CartWithValidationIssues.Cart);
            return(RedirectToAction("CreateSubscription", "Checkout"));
        }