Developer forum

Forum » Rapido » Preselect shipping provider when only one exist

Preselect shipping provider when only one exist

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars

Hi there,

I have a site with a bunch of countries. For each country I have two shipping providers. In a subscriber I determine which of the two I can show (based on the contents of the cart). So ultimately, the user only sees one shipping provider for its own ship-to country.

What is the best way to apply this to the order automatically? In a Rapido template I can easily preselect the option so in the UI it shows up as selected. However, that only sets the selected option in the UI but doesn't update the cart to show the associated shipping fee. For that, another submit to the cart page is needed.

Is there a way (server side or otherwise) to select the gateway an assign it to the order before the cart is rendered? One lousy way would be to register some JavaScript that reloads the cart when the order doesn't have s hipping method yet, but that feels a bit bad.

Thanks in advance!


Jannich Ariyanayagam
Jannich Ariyanayagam

Hi Imar,

Not sure if this helps but you could set the shipping method on a order with a custom function (depending on how many times you want to use it, otherwise just map the fields of the cart/order) in a notification subscriber (like BeforeRenderingNewStep) where you have the order object.

internal void SetShippingMethod(Shipping shipping, ref Order cart, string country)
      cart.ShippingMethodId = shipping.Id;
      cart.ShippingMethod = shipping.Name;
      cart.ShippingMethodDescription = shipping.Description;
      cart.ShippingMethodCountryCode = shipping.get_CountryRelation(country).Code2;

And use it like this:  SetShippingMethod(shipping, ref order, user.Country);

But this also requires you to have the DW ShippingMethod for the specific country in the same subscriber and parse it down to the "SetShippingMethod" with current user country.

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars

Thanks Jannich, I'll explore that as an option.


You must be logged in to post in the forum