protected CountryPreferenceModel PrepareCountryPreferenceModel() { var selectedCountry = _workContext.CurrentCountry; var countries = _shippingService.GetActiveCountries(); var options = _shippingService.GetShippingOptionByCountryAndEnabled(selectedCountry.Id, true); var freeDeliveryOption = options.Where(x => x.FreeThreshold > 0).FirstOrDefault(); var freeDeliveryNote = ", FREE Delivery*"; if (selectedCountry.ISO3166Code != "GB") { freeDeliveryNote = freeDeliveryOption == null ? string.Empty : string.Format(", FREE {0} over {1}", freeDeliveryOption.Name, _priceFormatter.FormatPrice(freeDeliveryOption.FreeThreshold)); } var model = new CountryPreferenceModel { SelectedCountryName = selectedCountry.Name, SelectedCountryCode = selectedCountry.ISO3166Code, FreeDeliveryNote = freeDeliveryNote }; model.Note = string.Format("Delivery options are set based on shipping to <b>{0}</b>, but can be amended below.", selectedCountry.Name); model.AvailableCountries = countries .Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = x.Id == selectedCountry.Id }) .ToList(); return(model); }
public ActionResult ChangeCountryPreference(CountryPreferenceModel model, string returnUrl = "") { var country = _shippingService.GetCountryById(model.CountryId); if (country != null) { _workContext.CurrentCountry = country; } var profileId = _workContext.CurrentProfile.Id; var options = _cartService.GetCustomerShippingOptionByCountryAndPriority(profileId); // Select default option _utilityService.SaveAttribute(profileId, "Profile", SystemCustomerAttributeNames.SelectedShippingOption, options[0].Id.ToString()); // Home page if (string.IsNullOrEmpty(returnUrl)) { returnUrl = Url.RouteUrl("Home"); } // Prevent open redirection attack if (!Url.IsLocalUrl(returnUrl)) { returnUrl = Url.RouteUrl("Home"); } return(Redirect(returnUrl)); }