+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / Retrieve Shipping Options Programmatically

Retrieve Shipping Options Programmatically

10 posts, 1 answered
  1. Craig
    Craig avatar
    4 posts
    Registered:
    07 Dec 2011
    01 Mar 2012
    Link to this post
    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
  2. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    02 Mar 2012
    Link to this post
    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();
    }
    Answered
  3. Craig
    Craig avatar
    4 posts
    Registered:
    07 Dec 2011
    02 Mar 2012
    Link to this post
    Thanks for the code sample, Jochem! This will definitely help me get started.

    Craig
  4. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    02 Mar 2012
    Link to this post
    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.
  5. Craig
    Craig avatar
    4 posts
    Registered:
    07 Dec 2011
    03 Mar 2012
    Link to this post
    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
  6. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    03 Mar 2012
    Link to this post
    @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.
  7. Craig
    Craig avatar
    4 posts
    Registered:
    07 Dec 2011
    05 Mar 2012
    Link to this post
    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
  8. Abubakar
    Abubakar avatar
    1 posts
    Registered:
    15 Jun 2012
    15 Jun 2012
    Link to this post
    sir i want eCommerce application complte project/ code plz provide me 
    i want sample code for online application coding 
  9. OC
    OC avatar
    129 posts
    Registered:
    17 Nov 2004
    20 Nov 2012
    Link to this post
    Hi, has anyone any insight in how to include the custom shipping methods into this?

    OC
  10. Sitefinity MartinM
    Sitefinity MartinM avatar
    4 posts
    Registered:
    20 Nov 2012
    23 Nov 2012
    Link to this post
    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
10 posts, 1 answered