public ShoppingCartModel() { Items = new List <ShoppingCartItemModel>(); Warnings = new List <string>(); EstimateShipping = new EstimateShippingModel(); DiscountBox = new DiscountBoxModel(); GiftCardBox = new GiftCardBoxModel(); CheckoutAttributes = new List <CheckoutAttributeModel>(); OrderReviewData = new OrderReviewDataModel(); ButtonPaymentMethodActionNames = new List <string>(); ButtonPaymentMethodControllerNames = new List <string>(); ButtonPaymentMethodRouteValues = new List <RouteValueDictionary>(); }
public ShoppingCartModel() { Items = new List<ShoppingCartItemModel>(); Warnings = new List<string>(); EstimateShipping = new EstimateShippingModel(); DiscountBox = new DiscountBoxModel(); GiftCardBox = new GiftCardBoxModel(); CheckoutAttributes = new List<CheckoutAttributeModel>(); OrderReviewData = new OrderReviewDataModel(); ButtonPaymentMethodActionNames = new List<string>(); ButtonPaymentMethodControllerNames = new List<string>(); ButtonPaymentMethodRouteValues = new List<RouteValueDictionary>(); }
public ActionResult GetEstimateShipping(EstimateShippingModel shippingModel, FormCollection form) { var cart = _workContext.CurrentCustomer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .Where(sci => sci.StoreId == _storeContext.CurrentStore.Id) .ToList(); //parse and save checkout attributes ParseAndSaveCheckoutAttributes(cart, form); var model = new ShoppingCartModel(); model.EstimateShipping.CountryId = shippingModel.CountryId; model.EstimateShipping.StateProvinceId = shippingModel.StateProvinceId; model.EstimateShipping.ZipPostalCode = shippingModel.ZipPostalCode; PrepareShoppingCartModel(model, cart,setEstimateShippingDefaultAddress: false); if (cart.RequiresShipping()) { var address = new Address() { CountryId = shippingModel.CountryId, Country = shippingModel.CountryId.HasValue ? _countryService.GetCountryById(shippingModel.CountryId.Value) : null, StateProvinceId = shippingModel.StateProvinceId, StateProvince = shippingModel.StateProvinceId.HasValue ? _stateProvinceService.GetStateProvinceById(shippingModel.StateProvinceId.Value) : null, ZipPostalCode = shippingModel.ZipPostalCode, }; GetShippingOptionResponse getShippingOptionResponse = _shippingService.GetShippingOptions(cart, address); if (!getShippingOptionResponse.Success) { foreach (var error in getShippingOptionResponse.Errors) model.EstimateShipping.Warnings.Add(error); } else { if (getShippingOptionResponse.ShippingOptions.Count > 0) { foreach (var shippingOption in getShippingOptionResponse.ShippingOptions) { var soModel = new EstimateShippingModel.ShippingOptionModel() { Name = shippingOption.Name, Description = shippingOption.Description, }; //calculate discounted and taxed rate Discount appliedDiscount = null; decimal shippingTotal = _orderTotalCalculationService.AdjustShippingRate(shippingOption.Rate, cart, out appliedDiscount); decimal rateBase = _taxService.GetShippingPrice(shippingTotal, _workContext.CurrentCustomer); decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency); soModel.Price = _priceFormatter.FormatShippingPrice(rate, true); model.EstimateShipping.ShippingOptions.Add(soModel); } } else { model.EstimateShipping.Warnings.Add(_localizationService.GetResource("Checkout.ShippingIsNotAllowed")); } } } return View(model); }