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 Result <SetShippingModel> SetShippingMethods(SetShippingArgs setShippingArgs) { var result = new Result <SetShippingModel>(); try { result.SetResult( new SetShippingModel { Success = true }); var currentCart = this.CartManager.GetCurrentCart( this.StorefrontContext.ShopName, this.VisitorContext.ContactId); if (!currentCart.ServiceProviderResult.Success) { result.SetErrors(currentCart.ServiceProviderResult); return(result); } var cart = currentCart.Result; var partyEntityList = this.EntityMapper.MapToPartyEntityList(setShippingArgs.ShippingAddresses); var shippingOptionType = ConnectOptionTypeHelper.ToShippingOptionType(setShippingArgs.OrderShippingPreferenceType); var shippingInfo = this.EntityMapper.MapToShippingInfoArgumentList(setShippingArgs.ShippingMethods); var managerResponse = this.CartManager.AddShippingInfo(cart, partyEntityList, shippingOptionType, shippingInfo); if (!managerResponse.ServiceProviderResult.Success) { result.SetErrors(managerResponse.ServiceProviderResult); return(result); } } catch (Exception ex) { result.SetErrors(nameof(this.SetShippingMethods), ex); } return(result); }