Developer forum

Forum » Development » Set StateId in CreateOrder

Set StateId in CreateOrder

Martin Moen
Reply

Isn't it possible to set the order state when creating order from webapi?

Ex.:
/dwapi/ecommerce/carts/{secret}/createorder

If I set this in the body of the post:

{"StateId":"OS10"}

I get this back:

"StateId": "OS1"

So it looks like the state id is ignored when creating order.


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Martin

It will set it, but the actual conversion from cart to order is overwriting it with the default orderstate later in the process.

Can you ellaborate on the use case - so we can find out how to implement something to make it possible. Maybe a specific UpdateOrderState endpoint would be beneficial as it could be used in other scenarios. Alternatively this endpoint would need to figure out when not to set default orderstate - either by adding another parameter or by convention when an orderstateid is posted to that endpoint.

Thoughts?

BR Nicolai

 
Martin Moen
Reply

Hi Nicolai!

Okay, that explains why I cant get it to work. Would be of great help if small things like this is better documented.

The scenario is connected to one of our headless solutions. For regular orders we are totally fine with setting the default state.

In the basket the customers can add a custom delivery date, and we have a feature that check directly into the ERP if there already is an order on the same date. If the customer already have an order on that date, they have the option to add the orderlines to the order directly.

In this scenario we do not create an order in DW, we update directly in the ERP. Now we see that it would be good to have these suppliment orders in DW. But if we add a regular order, it will be handled by the batch order integration, since we have set it up to transfer all orders with state "New".

So it would be great if we could just create the orders normally, but set state "Updated", set the same "IntegrationOrderId" and keep them in DW as backup/log orders.

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Thanks for explaining.

Should that logic maybe handled by notification subscribers? Or is everything handled in the JS app?

 
Martin Moen
Reply

Could be solved in a subscriber, but the problem is that DW dont really know which orders are regular orders and update orders.
Thats why we wanted to use the state.

But I guess we can use a custom field on the order, combined with a subscriber.
Which subscriber do you recommend? I guess it has to be done after the order has been saved and default state has been set?

 

You must be logged in to post in the forum