public ActionResult ShippingEstimate(ShippingEstimateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            // Add the estimate partial address to the checkout context so that we can use that later to display rates if there is no customer address
            var customer                = HttpContext.GetCustomer();
            var checkoutContext         = PersistedCheckoutContextProvider.LoadCheckoutContext(customer);
            var shippingEstimateDetails = new ShippingEstimateDetails(
                country: model.Country,
                city: model.City,
                state: model.State,
                postalCode: model.PostalCode);

            var updatedCheckoutContext = new PersistedCheckoutContext(
                creditCard: checkoutContext.CreditCard,
                payPalExpress: checkoutContext.PayPalExpress,
                purchaseOrder: checkoutContext.PurchaseOrder,
                braintree: checkoutContext.Braintree,
                termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted,
                over13Checked: checkoutContext.Over13Checked,
                amazonPayments: checkoutContext.AmazonPayments,
                shippingEstimateDetails: shippingEstimateDetails,
                offsiteRequiresBillingAddressId: checkoutContext.OffsiteRequiresBillingAddressId,
                offsiteRequiresShippingAddressId: checkoutContext.OffsiteRequiresShippingAddressId,
                email: checkoutContext.Email,
                selectedShippingMethodId: checkoutContext.SelectedShippingMethodId);

            PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext);

            return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
        }
        ShippingEstimateViewModel BuildViewModel(ShippingEstimateDetails shippingEstimateDetails, bool showNoRates)
        {
            if (shippingEstimateDetails == null)
            {
                shippingEstimateDetails = new ShippingEstimateDetails(
                    country: null,
                    city: null,
                    state: null,
                    postalCode: null);
            }

            var countries = AddressSelectListBuilder.BuildCountrySelectList(shippingEstimateDetails.Country);
            var states    = AddressSelectListBuilder.BuildStateSelectList(countries.SelectedValue.ToString(), shippingEstimateDetails.State);

            return(new ShippingEstimateViewModel
            {
                Country = shippingEstimateDetails.Country,
                Countries = countries,
                City = shippingEstimateDetails.City,
                State = shippingEstimateDetails.State,
                States = states,
                PostalCode = shippingEstimateDetails.PostalCode,
                ShowNoRates = showNoRates,
                ShippingCalculationRequiresCityAndState = Shipping.GetActiveShippingCalculationID() != Shipping.ShippingCalculationEnum.UseRealTimeRates
            });
        }
        IEnumerable <object> GetAddressState(Address address, ShippingEstimateDetails shippingEstimateDetails = null)
        {
            // Non-null addresses track the address type plus the basic address fields
            if (address != null)
            {
                return new object[]
                       {
                           (int)address.AddressType,
                           address.Address1,
                           address.Address2,
                           address.City,
                           address.State,
                           address.Zip,
                           address.Country,
                       }
            }
            ;

            if (shippingEstimateDetails != null)
            {
                return new object[]
                       {
                           0,
                           0,
                           0,
                           shippingEstimateDetails.City,
                           shippingEstimateDetails.State,
                           shippingEstimateDetails.PostalCode,
                           shippingEstimateDetails.Country,
                       }
            }
            ;

            // Null addresses are treated as a collection of zeroes
            return(new object[]
            {
                0,
                0,
                0,
                0,
                0,
                0,
                0,
            });
        }
    }
        public ActionResult ShippingEstimate(ShippingEstimateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            // Add the estimate partial address to the checkout context so that we can use that later to display rates if there is no customer address
            var customer = HttpContext.GetCustomer();
            var shippingEstimateDetails = new ShippingEstimateDetails(
                country: model.Country,
                city: model.City,
                state: model.State,
                postalCode: model.PostalCode);

            var updatedPersistedCheckoutContext = new PersistedCheckoutContextBuilder()
                                                  .From(PersistedCheckoutContextProvider.LoadCheckoutContext(customer))
                                                  .WithShippingEstimate(shippingEstimateDetails)
                                                  .Build();

            PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedPersistedCheckoutContext);

            return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
        }
 public PersistedCheckoutContextBuilder WithShippingEstimate(ShippingEstimateDetails shippingEstimate)
 {
     ShippingEstimate    = shippingEstimate;
     ShippingEstimateSet = true;
     return(this);
 }