Developer forum

Forum » Development » Change the shipping method programmatically

Change the shipping method programmatically

Gaetan Di Caro
Reply

Hello,

 

I'm having some trouble making coexist 2 different shops on the same country with each their own shipping method. I'm not having any luck with the configuration so I'm trying to set it programmatically. I was thinking of setting it either in the feeprovider or in a cart observer.

However I can't seem to find a mathod to do that. It is easy to get the right shipping method object, but I can't find anything in the Order object or otherwise to set it. Order has "ShippingMethod", but it is only a string, as well as "ShippingMethodID", which behaves erratically if I try to change it.

Any idea how this could be done ?

 

Thanks !


Replies

 
Nicolai Høeg Pedersen
Reply

You can configure that directly on the cart instance. See dump.

I do not think you can do that using subscribers. You can also simply do it in a Razor template using conditionals.

BR Nicolai

Capture.PNG
 
Gaetan Di Caro
Reply

Hi Nicolai,

My cart is configured like that but it doesn't work. My guess is that it's because my two websites are on the same country. Since my user cannot choose a shipping method in the interface (it should be by default), the default shipping for this country is chosen instead. I have a bug case on this (113249).

How would I go changing the shipping method directly in the template ?

Thanks !

 
Kristian Kirkholt
Reply

Hi Gaetan

A shipping method is bound to a country. So when you in the orderflow get the Information template you should be able to choose country and get shipping methods allowed in this.

Also you can preset the selection in -> Management Center -> Ecommerce -> Advanced Configuration -> Shopping Carts -> Use default methods before the user selects them

Please feel free to write on the case 113249 if you have further questions regarding this.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 
Gaetan Di Caro
Reply

Indeed, and I have done all that. However it still doesn't work, because both my shops are on the same country. If I choose a default shipping method for the country, this shipping method will be selected by default for both shops, regardless of how I configured the basket paragraph. And if I don't use a default method, then no method at all is applied (I don't have a step for that in the order process, as the method should be applied by default)

 
Kristian Kirkholt
Reply
This post has been marked as an answer

Okay you got different shipping methods on same country, but would like to make customer shipping methods base this on shops.

At the moment this is not an option in Dynamicweb, but as a workaround you could make "dummy" country for shipping methods if you are not going to show this to customer anyway.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

Votes for this answer: 1
 
Kim Søjborg Pedersen
Reply

Hi Gaetan,
have you tried setting it directly in the the razor template like this

Dynamicweb.eCommerce.Common.Context.Cart.ShippingMethod = "SHIP1";

 
Gaetan Di Caro
Reply

Doesn't work unfortunately. I don't know how the code is written but if I set ShippingMethod or ShippingMethodID, it behaves erratically (maybe they should be readonly).

 
Gaetan Di Caro
Reply

That could be an idea ! If I create a new country in Management Center>Ecommerce>Internationalization>Countries, would that affect my products or users for the localization ? I wouldn't think so since it's on the website level.

I'll try that

 
Gaetan Di Caro
Reply

It seems to work by creating a dummy country ! I'll have to fiddle here and there but this seems to be a workaround that works

 

You must be logged in to post in the forum