GetCustomShippingMethods
Hi.
I'm trying to make a shipping calculator for a site, and need to access the Custom Shipping methods.
I'm getting a hard time implementing this function:
private IList<IShippingResponse> GetCustomShippingMethods() ShippingManager manager = ShippingManager.GetManager(); ParameterExpression parameterExpression = Expression.Parameter(typeof(ShippingMethod), "x"); ParameterExpression[] parameterExpressionArray = new ParameterExpression[1]; parameterExpressionArray[0] = parameterExpression; List<ShippingMethod> list = manager.GetShippingMethods().Where<ShippingMethod>(Expression.Lambda<Func<ShippingMethod, bool>>(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(get_IsActive)), parameterExpressionArray)).ToList<ShippingMethod>(); List<IShippingResponse> shippingResponses = new List<IShippingResponse>(); List<IShippingResponse> shippingResponses1 = shippingResponses; IEnumerable<GenericShippingResponse> genericShippingResponses = list.Select<ShippingMethod, GenericShippingResponse>(new Func<ShippingMethod, GenericShippingResponse>(this.CalculateShippingMethod)); shippingResponses1.AddRange(genericShippingResponses.Where<GenericShippingResponse>((GenericShippingResponse x) => x != null)); return shippingResponses;Hi Ole,
Thank you for contacting Telerik Support!
In the Ecommerce module there are shipping carriers, which expose shipping services, and shipping methods. The shipping carriers are third parties, like FedEx, UPS, etc. The shipping methods are created from the backend under Ecommerce -> Shipping methods.
To get the shipping methods that you have created in the backend, you can use the following code:
public static IList<ShippingMethod> GetShippingMethods() ShippingManager manager = ShippingManager.GetManager(); List<ShippingMethod> shippingMethods = manager.GetShippingMethods().Where(m => m.IsActive).ToList(); return shippingMethods;public static IList<IShippingResponse> GetShippingCarrierServices() ShippingManager shippingManager = ShippingManager.GetManager(); List<IShippingResponse> availableShippingServices = new List<IShippingResponse>(); //Get the shipping carriers and iterate through them. foreach (var shippingCarrier in Config.Get<ShippingConfig>().ShippingCarrierProviders.Values.Where(x => x.IsActive)) //Get an instance of the shipping carrier provider. var carrierProvider = shippingManager.GetShippingCarrierProvider(shippingCarrier.Name); //Get the shipping service that corresponds to the countries you want to ship between, and to the weight. //The ShippingResponseContext contains the available services for the specified locations and weight. //Note that you have to pass the appropriate country codes according to the shipping carriers. You can find them on the carriers' sites. ShippingResponseContext shippingContext = carrierProvider.GetServiceRates(CreateShippingRequest("fromCountry", "fromZip", "toCountry", "toZip", 100)); if (shippingContext.ShippingResponses != null) //Each shipping response object has a property representing the rate of the service. availableShippingServices.AddRange(shippingContext.ShippingResponses); return availableShippingServices;public static IShippingRequest CreateShippingRequest(string shipFromCountry, string shipFromZip, string shipToCountry, string shipToZip, double totalWeight) GenericShippingRequest request = new GenericShippingRequest(shipFromCountry, shipFromZip, shipToCountry, shipToZip, totalWeight); return request;Martin,
Thanks. But I have suggested a PITS issue that you make this like for the shipping carriers. One code snipplet should return all sipping options.
OC
Hello Ole,