Developer forum

Forum » Ecommerce - Standard features » RE: Change Prices on orderlines

RE: Change Prices on orderlines

Paul Nilsson
Reply

I whant to change the price for the produkts in the cart.

I have tryed both the OrderTemplateExtender and the OrdetLineTemplateExtender but it the prices will not save to the database or even change in the cart.

I hardecoded one orderline and manage to change it once but when I tryed to change another orderline it dodn't work and I coulden't change the first one anymore.

I have even tryed the different "cart observers" but with no luck.

This is the code I used the one time I managed to get it to work:

var test = OrderLine.GetOrderLineByID("OL897");
test.SetUnitPrice(777);
test.Save();
Dynamicweb.eCommerce.Frontend.Cart.CartCatch.SaveCart(); 

What extender or observer should I use and what is wrong whit the code above?

 


Replies

 
Nicolai Høeg Pedersen
Reply

You should use a price provider or discount.

Or set the OrderLine.AllowOverridePrices to True to avoid Dynamicweb will recalculate the price.

 
Paul Nilsson
Reply

I tryed to set OrderLine.AllowOverridePrices to True but it didn't seem to make any difference.

Can you manipulate the orderlines from the priceprovider or discount?

The senario where I whant to shaange the price is when I have two lines that have the same product and the quantity is over a surtain amount you get a lower price.
Over 10st = 2kr

Over 100st = 1kr

But if this is in two order lines like:

Orderline1, Product1, 8st, 2kr
Orderline2, Product1, 95st, 1kr

Since the total amount is over 100 I would like to set the price for orderline1 to 1kr.

Resukting in:

Orderline1, Product1, 8st, 1kr
Orderline2, Product1, 95st, 1kr

 

 

 

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Well, you can just do that using the price matrix.http://manual.dynamicweb-cms.com/Default.aspx?ID=7155#30152

Just checked you code...

You load the orderline from the databsae, see orange bit. Then you save the cart already in the session to the database overriding the changes you just made, see red bit. You should find the orderline from the eCommerce.Common.Context.Cart.Orderlines property and change the value there.

var test = OrderLine.GetOrderLineByID("OL897");
test.SetUnitPrice(777);
test.Save();

Dynamicweb.eCommerce.Frontend.Cart.CartCatch.SaveCart(); 

Votes for this answer: 1
 
Paul Nilsson
Reply

I am allready using the price matrix.

So how do a get from "eCommerce.Common.Context.Cart.Orderlines" to the orderline that I whant to change?

I can't seem to find the where I can get the orderline by id.

 
Nicolai Høeg Pedersen
Reply

Just iterate them and check on the orderline id or use a LINQ expression.

 
Paul Nilsson
Reply

I just tested it and it works.

Thanks
 

 
Nicolai Høeg Pedersen
Reply

Great - glad to hear!

 

You must be logged in to post in the forum