Developer forum

Forum » Development » How to change orderline price after orderline added?

How to change orderline price after orderline added?

Allan Iversen
Reply

We got a webshop running, where specific customer got their own prices, but if they start shopping before logging in - the orderline price is just the default.

 

It isn't updated the product price delivered from our price provider.

 

 

Is it possible to update these prices using DW standard - checkboxes? - if not, where and how should we change these prices?

 

 

I am thinking of something like this, but where to run this?:

foreach (OrderLine orderLine in order.OrderLines)
{
  orderLine.SetUnitPrice(orderLine.Product.Price, true);
}

 

 

 


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Allan,

 

Currently, there is no checkbox to recalculate the entire cart when a user logs in with an existing cart in the context, although it would make sense to have such an option. I have added this feature request to our Backlog (#13888).

 

In the meantime, you will have to do some magic of you own. I would not recommend implementing the solution you propose as it would change the type of the orderline. I would do this:

foreach (var ol in order.OrderLines)
{
	// Verify that this is a product line
	if (ol.Type != ((int)OrderLineType.Product).ToString())
		continue;
	
	// Set UnitPrice property as this will not change the type of the OrderLine
	// The actual price does not matter as the price will be calculated next time
	// unless the order is no longer a cart
	ol.UnitPrice = ol.Product.Price;
}
order.ClearCachedPrices();

 

Hope this helps :)

 

- Jeppe

Votes for this answer: 1

 

You must be logged in to post in the forum