Developer forum

Forum » Templates » Set order state by code

Set order state by code

Alexander Tømmerholen
Reply

Hi,

Is it possible to set order state by code? Have tried to do it in the same way you can set order context

<input type="hidden" name="OrderContext" value="ORDERCONTEXT1">
<input type="hidden" name="StateId" value="OS12">

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

In what context?

When adding to cart? Then you cannot.

 
Alexander Tømmerholen
Reply

When you complete the order. So, going from a cart to an actual order.

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Any reason you cannot swicth default order state in the backend? Do you have different states on different new orders in the same orderflow?

You can setup multiple flows and apply those flows to different shops.

 
Alexander Tømmerholen
Reply

Well, yes

We send out an mail when a customer completes an order in the default order context and get the order state new. Set up like this:

 

When a customer completes an order in the second order context we need to send out two different emails (one to customer and one to dealer). We are trying to set up an click and collect cart and a normal cart. The reason for not sending the same email is because we need to have different content in the emails. Normally this could be solved with two cart apps and by using the normal notifications settings within the app, but we have an integration to "Klarna" (payment provider). When we get a callback from "Klarna" and complete the order by code the normal way of setting up order emails do not work (at least we have not been able to make it work). Because of this we have set up that the order confirmation mail gets sent when the order get the state new. 

I would like that orders completed in the click and collect context to get the order state "clickAndCollect" and through that use the normal notifications settings in the cart app to send out the order confirmation to customer and dealer.  

We only have one shop so we are not able to set up a different flow. 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

You can create 2 different orderflows and assign them to 2 different shops. On the cart instance you can set the shopid for a given order - so if you create 2 cart setups using the same template, you can set different shops and hence different orderflows.

Alternatively you can manually set the orderstate using OrderService.UpdateCartState(Order cart, string stateId) before completing the order - as long as it is cart.

 

You must be logged in to post in the forum