Developer forum

Forum » Development » Getting the current order in backend code

Getting the current order in backend code

Hans Kloppenborg
Reply

Hi,

We are normally using the following code te get the current order from the Context:

Context.CartContext = OrderContext.GetOrderContextById(StringConstants.ApplicationVariables.DefaultOrderContextId);
return Context.Cart;

After having troubles with concurrency violations, some of which point to this code, and inspecting the underlying code with dot peek, it seems that the Context.Cart call itself does a save operation on the cart/order. 

Should we be using another method to get the current cart/order?

Should a get operation at any time somehow be a save also?

As a recent experiment we have added the line

Context.LoadUserContextCarts();

before the Context.Cart call, this seems to help but we are not sure if this is 100% foolproof.

Please let us know what the correct method is.

Greets Hans


Replies

 
Alexey Tanchenko Dynamicweb Employee
Alexey Tanchenko
Reply

Hi,

"Should we be using another method to get the current cart/order?"
- No, you shouldn't. But if it not working as expected in your case, I'd like to get more details.

"Should a get operation at any time somehow be a save also?"
- Yes, in this case it should. Since during the cart loading several of its properties may be changed (e.g. price/discount was changed) - all changes must be changed/recalculated and saved to database.

"Context.LoadUserContextCarts();"
- I am not sure that you need to perform it, since it is called anyway when user logging in.

 

Best regards,
Alexey

 
Peter Leleulya
Reply

It is a shop for anonymous users, no log-in on the website at all ...

 

You must be logged in to post in the forum