public JsonResult GetShippingMethods(GetShippingMethodsInputModel inputModel) { try { Assert.ArgumentNotNull(inputModel, "inputModel"); var validationResult = new BaseJsonResult(); this.ValidateModel(validationResult); if (validationResult.HasErrors) { return Json(validationResult, JsonRequestBehavior.AllowGet); } var response = this.ShippingManager.GetShippingMethods(CurrentStorefront, CurrentVisitorContext, inputModel); var result = new ShippingMethodsJsonResult(response.ServiceProviderResult); if (response.ServiceProviderResult.Success && response.Result != null) { result.Initialize(response.ServiceProviderResult.ShippingMethods, response.ServiceProviderResult.ShippingMethodsPerItems); } return Json(result, JsonRequestBehavior.AllowGet); } catch (Exception e) { CommerceLog.Current.Error("GetShippingMethods", this, e); return Json(new BaseJsonResult("GetShippingMethods", e), JsonRequestBehavior.AllowGet); } }
private void AddShippingMethodsToResult(CheckoutDataBaseJsonResult result, CommerceCart cart) { var shippingRequest = new GetShippingMethodsInputModel { ShippingPreferenceType = ShippingOptionType.None.Name }; var response = this.ShippingManager.GetShippingMethods(this.CurrentStorefront, this.CurrentVisitorContext, shippingRequest); if (response.ServiceProviderResult.Success && response.Result != null) { foreach (var sm in response.Result) { var isEmailMethod = sm.GetPropertyValue("IsEmailShippingMethod") != null && (bool)sm.GetPropertyValue("IsEmailShippingMethod"); var isShipToStoreMethod = sm.GetPropertyValue("IsShipToStoreShippingMethod") != null && (bool)sm.GetPropertyValue("IsShipToStoreShippingMethod"); if (isEmailMethod) { result.EmailDeliveryMethod = sm; } if (isShipToStoreMethod) { result.ShipToStoreDeliveryMethod = sm; } } return; } result.EmailDeliveryMethod = new ShippingMethod(); result.ShipToStoreDeliveryMethod = new ShippingMethod(); result.SetErrors(response.ServiceProviderResult); }