public async virtual Task <ShippingMethodTypesViewModel> GetShippingMethodTypesAsync(GetShippingMethodsParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } var shippingMethods = await GetFulfillmentMethods(param).ConfigureAwait(false); if (shippingMethods == null) { return(null); } var shippingMethodTypeViewModels = shippingMethods .Select(sm => CartViewModelFactory.GetShippingMethodViewModel(sm, param.CultureInfo)) .Where(FilterShippingMethodView) .GroupBy(sm => sm.FulfillmentMethodType) .Select(type => CartViewModelFactory.GetShippingMethodTypeViewModel(type.Key, type.ToList(), param.CultureInfo)) .OrderBy(OrderShippingMethodTypeView) .ToList(); return(new ShippingMethodTypesViewModel { ShippingMethodTypes = shippingMethodTypeViewModels }); }
/// <summary> /// Estimates the shipping method. Does not save the cart. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual async Task <ShippingMethodViewModel> EstimateShippingAsync(EstimateShippingParam param) { if (param == null) { throw new ArgumentNullException("param"); } if (param.CultureInfo == null) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CultureInfo"), "param"); } if (param.Cart == null) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Cart"), "param"); } var shippingMethods = await GetShippingMethodsForShippingEstimationAsync(param); var selectedMethod = GetCheapestShippingMethodViewModel(shippingMethods); var firstShipment = GetShipment(param.Cart); if (param.ForceUpdate || firstShipment.FulfillmentMethod == null) { firstShipment.FulfillmentMethod = selectedMethod; } var vm = CartViewModelFactory.GetShippingMethodViewModel(firstShipment.FulfillmentMethod, param.CultureInfo); return(vm); }
/// <summary> /// Get the Shipping methods available for a shipment. /// </summary> /// <param name="param"></param> /// <returns>The ShippingMethodsViewModel</returns> public async virtual Task <ShippingMethodsViewModel> GetShippingMethodsAsync(GetShippingMethodsParam param) { if (param == null) { throw new ArgumentNullException("param", "param is required"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException("param.Scope is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo is required", "param"); } var shippingMethods = await GetFulfillmentMethods(param).ConfigureAwait(false); if (shippingMethods == null) { return(null); } var shippingMethodViewModels = shippingMethods .Select(sm => CartViewModelFactory.GetShippingMethodViewModel(sm, param.CultureInfo)).ToList(); return(new ShippingMethodsViewModel { ShippingMethods = shippingMethodViewModels }); }
/// <summary> /// Get the Shipping methods available for a shipment. /// </summary> /// <param name="param"></param> /// <returns>The ShippingMethodsViewModel</returns> public async virtual Task <ShippingMethodsViewModel> GetShippingMethodsAsync(GetShippingMethodsParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } var shippingMethods = await GetFulfillmentMethods(param).ConfigureAwait(false); if (shippingMethods == null) { return(null); } var shippingMethodViewModels = shippingMethods .Select(sm => CartViewModelFactory.GetShippingMethodViewModel(sm, param.CultureInfo)) .ToList(); return(new ShippingMethodsViewModel { ShippingMethods = shippingMethodViewModels }); }