public Result <ShippingModel> GetShippingMethods(GetShippingArgs getShippingArgs) { var model = new ShippingModel(); var result = new Result <ShippingModel>(); try { result.SetResult(model); var currentCart = this.CartManager.GetCurrentCart( this.StorefrontContext.ShopName, this.VisitorContext.ContactId); if (!currentCart.ServiceProviderResult.Success) { result.SetErrors(currentCart.ServiceProviderResult); return(result); } var shippingOptionType = ConnectOptionTypeHelper.ToShippingOptionType(getShippingArgs.ShippingPreferenceType); PartyEntity address = null; if (getShippingArgs.ShippingAddress != null) { address = this.EntityMapper.MapToPartyEntity(getShippingArgs.ShippingAddress); } var shippingMethods = this.ShippingManager.GetShippingMethods( this.StorefrontContext.ShopName, currentCart.Result, shippingOptionType, address, null); if (!currentCart.ServiceProviderResult.Success) { result.SetErrors(currentCart.ServiceProviderResult); return(result); } result.Data.ShippingMethods = new List <ShippingMethodModel>(); foreach (var shippingMethod in shippingMethods.ServiceProviderResult.ShippingMethods) { var shippingModel = this.EntityMapper.MapToShippingMethodModel(shippingMethod); result.Data.ShippingMethods.Add(shippingModel); } } catch (Exception ex) { Log.Error(ex.Message, ex, this); result.SetErrors(nameof(this.GetShippingMethods), ex); } return(result); }
public ActionResult GetShippingMethods() { var shippingArgs = new GetShippingArgs { ShippingPreferenceType = "1" }; var result = this.deliveryRepository.GetShippingMethods(shippingArgs); if (result.Success) { return(this.JsonOk(result.Data)); } return(this.JsonError(result.Errors?.ToArray(), HttpStatusCode.InternalServerError, tempData: result.Data)); }