Esempio n. 1
0
        private CheckoutViewModel InitializeCheckoutViewModel(CheckoutPage currentPage, CheckoutViewModel viewModel)
        {
            var shipment             = _checkoutService.CreateShipment();
            var shippingRates        = _checkoutService.GetShippingRates(shipment);
            var shippingMethods      = GetShippingMethods(shippingRates);
            var selectedShippingRate = shippingRates.FirstOrDefault();
            var customer             = _customerContext.CurrentContact.CurrentContact;
            var paymentMethods       = _checkoutService.GetPaymentMethods();

            if (selectedShippingRate != null)
            {
                _checkoutService.UpdateShipment(shipment, selectedShippingRate);
            }
            else
            {
                ModelState.AddModelError("ShippingRate", _localizationService.GetString("/Checkout/Payment/Errors/NoShippingRate"));
            }

            if (viewModel == null)
            {
                var shippingMethod = shippingMethods.FirstOrDefault();
                viewModel = CreateCheckoutViewModel(paymentMethods.First(), shippingMethod == null ? Guid.Empty : shippingMethod.Id, customer);

                // Run the workflow once to calculate all taxes, charges and get the correct total amounts.
                _cartService.RunWorkflow(OrderGroupWorkflowManager.CartValidateWorkflowName);
            }
            else
            {
                // Countries and region lists are always lost during postbacks.
                // Therefor get all countries and regions for the billing address.
                _addressBookService.GetCountriesAndRegionsForAddress(viewModel.BillingAddress);

                // And get the countries and the regions for all other addresses as well.
                PopulateCountryAndRegions(viewModel, viewModel.BillingAddress);
            }

            viewModel.StartPage                = _contentLoader.Get <StartPage>(ContentReference.StartPage);
            viewModel.ReferrerUrl              = GetReferrerUrl();
            viewModel.CurrentPage              = currentPage;
            viewModel.PaymentMethodViewModels  = paymentMethods;
            viewModel.ShippingMethodViewModels = shippingMethods;
            viewModel.AvailableAddresses       = GetAvailableAddresses();
            viewModel.AppliedCouponCodes       = GetAppliedDiscountsWithCode().Select(d => d.DiscountCode).Distinct();

            return(viewModel);
        }
Esempio n. 2
0
        private CheckoutViewModel InitializeCheckoutViewModel(CheckoutPage currentPage, CheckoutViewModel viewModel)
        {
            var shipment             = _checkoutService.CreateShipment();
            var shippingRates        = _checkoutService.GetShippingRates(shipment);
            var shippingmethods      = GetShippingMethods(shippingRates);
            var selectedShippingRate = shippingRates.First();
            var customer             = _customerContext.CurrentContact.CurrentContact;
            var paymentMethods       = _checkoutService.GetPaymentMethods();

            _checkoutService.UpdateShipment(shipment, selectedShippingRate);

            if (viewModel == null)
            {
                viewModel = CreateCheckoutViewModel(paymentMethods.First(), shippingmethods.First().Id, customer);

                // Run the workflow once to calculate all taxes, charges and get the correct total amounts.
                _cartService.RunWorkflow(OrderGroupWorkflowManager.CartValidateWorkflowName);
            }
            else
            {
                // Countries and region lists are always lost during postbacks.
                // Therefor get all countries and regions for the billing address.
                _addressBookService.GetCountriesAndRegionsForAddress(viewModel.BillingAddress);

                // And get the countries and the regions for all other addresses as well.
                PopulateCountryAndRegions(viewModel, viewModel.BillingAddress);
            }

            viewModel.StartPage                = _contentLoader.Get <StartPage>(ContentReference.StartPage);
            viewModel.ReferrerUrl              = GetReferrerUrl();
            viewModel.CurrentPage              = currentPage;
            viewModel.PaymentMethodViewModels  = paymentMethods;
            viewModel.ShippingMethodViewModels = shippingmethods;
            viewModel.AvailableAddresses       = GetAvailableAddresses();

            return(viewModel);
        }