Developer forum

Forum » Development » Issues removing OrderLines

Issues removing OrderLines

Jacob
Reply

Hi,

We are having issues deleting orderlines in our order flow. We wish to delete select orderlines when the user travels backwards through our flow, so that we can add new orderlines with correct quantities when the user chooses to move forward once again.

Thus, when the user moves backwards, we loop through GetLoop("OrderLines") and remove the specific orderlines using the following line:

order.OrderLines.RemoveLine(orderLine.GetString("Ecom:Order:OrderLine.Id"));

This successfully removes the line, as order.OrderLines.Count properly decreases for every line we remove. However, the line still remains somewhere behind the scenes, and will still exist in the cart if the page is refreshed or if the user moves forward through the flow again, causing doubles to be added. We are not sure which save-method to use, thus we have tried all three of these lines of code after removing our orderlines:

orderService.Save(orderService.GetOrder(GetString("Ecom:Order.ID")));
order.OrderLines.Save(GetString("Ecom:Order.ID"));
Dynamicweb.Ecommerce.Frontend.Cart.CartCatch.SaveCart();

It appears as though the order is not being saved properly. Are we using the wrong save-method(s)? We have looked through our cookies, but perhaps there is some DW cache-method that we need to run to save our changes to the order/cart?

Thanks!

Kind regards,
Jacob & Team


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Jacob

It can be several things. Depending on what orderlines you add and remove and the type they are, Dynamicweb might not care and add them again - i.e. if it is a discount etc.

Also some of your code is not making sense:
orderService.Save(orderService.GetOrder(GetString("Ecom:Order.ID")));
This will get the order from database, and save it again right back - so you did not save anything except what was already there

order.OrderLines.Save(GetString("Ecom:Order.ID"));
This will save each record currently on the orderlines collection - and you just removed the ones you did not want - so you save what is already saved again

Dynamicweb.Ecommerce.Frontend.Cart.CartCatch.SaveCart();
This is the closest - it will save the current Common.Context.Cart instance to database.

It could also be that when you make changes to a cart - that you probably got from context.cart, you also have to "put it back":

myOrder = Common.Context.Cart;
//modify order object
//Save order object
orderService.Save(myOrder);
Common.Context.Cart = myOrder; //might be redundant depending on your code. Since this should be a reference.

That might solve the issue.

Try that or post all of your code so we can see it.

Thanks, Nicolai

Votes for this answer: 1
 
Jacob
Reply

Thank you, Nicolai! We managed to get it working using your examples :)

 

You must be logged in to post in the forum