public ActionResult IndexPost(EstimateShippingViewModel posted) { EstimateShippingViewModel model = BuildViewModel(); if (posted != null) { model.PostalCode = posted.PostalCode; model.CountryId = posted.CountryId; model.RegionId = posted.RegionId; } GetRates(model); return View(model); }
private EstimateShippingViewModel BuildViewModel() { EstimateShippingViewModel model = new EstimateShippingViewModel(); ViewBag.GetRatesButton = this.MTApp.ThemeManager().ButtonUrl("GetRates", Request.IsSecureConnection); ViewBag.Countries = MTApp.CurrentStore.Settings.FindActiveCountries(); if (SessionManager.CurrentUserHasCart(MTApp.CurrentStore)) { Order basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore); if (basket.ShippingAddress.CountryBvin != string.Empty) { model.CountryId = basket.ShippingAddress.CountryBvin; } if (basket.ShippingAddress.RegionBvin != string.Empty) { model.RegionId = basket.ShippingAddress.RegionBvin; } model.City = basket.ShippingAddress.City; model.PostalCode = basket.ShippingAddress.PostalCode; } return model; }
private void GetRates(EstimateShippingViewModel model) { if (SessionManager.CurrentUserHasCart(MTApp.CurrentStore) == true) { Order Basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore); if (Basket != null) { Basket.ShippingAddress.PostalCode = model.PostalCode; if (model.CountryId != string.Empty) { Country current = MerchantTribe.Web.Geography.Country.FindByBvin(model.CountryId); if (current != null) { Basket.ShippingAddress.CountryBvin = model.CountryId; Basket.ShippingAddress.CountryName = current.DisplayName; Basket.ShippingAddress.RegionBvin = model.RegionId; Basket.ShippingAddress.RegionName = model.RegionId; } } MTApp.OrderServices.Orders.Update(Basket); SortableCollection<ShippingRateDisplay> Rates; Rates = MTApp.OrderServices.FindAvailableShippingRates(Basket); if (Rates.Count < 1) { TempData["message"] = "Unable to estimate at this time"; } model.Rates = Rates.ToList(); } } }