Retrieve Shipping Options Programmatically
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
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();
Thanks for the code sample, Jochem! This will definitely help me get started.
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.
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
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 :)
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.
sir i want eCommerce application complte project/ code plz provide me
i want sample code for online application coding
Hi, has anyone any insight in how to include the custom shipping methods into this?
OC
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