Retrieve Shipping Options Programmatically

Posted by Community Admin on 05-Aug-2018 17:08

Retrieve Shipping Options Programmatically

All Replies

Posted by Community Admin on 01-Mar-2012 00:00

Is it possible to use the ecommerce shipping method service in Sitefinity 4.x in code-behind to retrieve the list of shipping options (including shipping prices) that is available in the pre-built checkout widget? I've searched for code examples but have not found anything yet.

Thanks in advance.

Craig

Posted by Community Admin on 02-Mar-2012 00:00

Hey Craig,

Hope this will help you get started...

private void GetShippingOptions()
    var availableShippingMethods = new List<IShippingResponse>();
 
    foreach (var shippingCarrier in Config.Get<ShippingConfig>().ShippingCarrierProviders.Values.Where(x => x.IsActive))
    
        var carrierProvider = this.ShippingManager.GetShippingCarrierProvider(shippingCarrier.Name);
 
        ShippingResponseContext shippingContext = carrierProvider.GetServiceRates(this.GenerateShippingRequest());
        if (shippingContext.ShippingResponses != null)
        
            availableShippingMethods.AddRange(shippingContext.ShippingResponses);
        
    
 
    availableShippingMethods = availableShippingMethods.OrderBy(x => x.SortOrder).ToList();
    shippingMethodsList.DataSource = availableShippingMethods;
    shippingMethodsList.DataBind();

Posted by Community Admin on 02-Mar-2012 00:00

Thanks for the code sample, Jochem! This will definitely help me get started.

Craig

Posted by Community Admin on 02-Mar-2012 00:00

If it works on monday, could you mark it as 'answer' then it won't show up no more in my feed list..
Thanks!

Jochem.

Posted by Community Admin on 03-Mar-2012 00:00

I appreciate the code very much. Although my FedEx shipping estimates work using the built-in widget, I'm getting some errors from GetServiceRates() on the custom code, but I'm digging into that now.

Thanks again,

Craig

Posted by Community Admin on 03-Mar-2012 00:00

@Craig

Feel free to toss it over here, sometimes 4 eyes see more than 2 who've been constantly staring...

And thanks for the checkbox - My new years resolution was to keep the ecommerce part of the forums the only one questionmark free :)

J.

Posted by Community Admin on 05-Mar-2012 00:00

The code is now working when passing in a GenericShippingRequest object to the GetServiceRates() method. My issue was an improperly formatted country code - the FedEx list can be found at http://www.fedex.com/gb/tracking/codes.html.

Craig

Posted by Community Admin on 15-Jun-2012 00:00

sir i want eCommerce application complte project/ code plz provide me 
i want sample code for online application coding 

Posted by Community Admin on 20-Nov-2012 00:00

Hi, has anyone any insight in how to include the custom shipping methods into this?

OC

Posted by Community Admin on 23-Nov-2012 00:00

Hi Ole,

We have already replied to the separate thread that you have opened. You can find our reply here.

Greetings,
Martin Mihailov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed