Developer forum
E-mail notifications
Change the orderline price
I am trying to change the orderline price. I have tried to change the orderline price with the orderline.SetUnitPrice(double Price), it works but it sets the Vat to some default value 25%. The also takes a SetUnitPrice(PriceInfo priceInfo) but I cant get it to work. Nothing happens when I sen in a price info to the SetUnitPrice.
I would like to change the orderline pricewithoutVat and then it should inherit the Vat from the Vat value before i changed it. How do i do this?
Kind regards!
/Magnus
Replies
Hi, pr.PriceWithoutVAT = 100; ol.SetUnitPrice(pr);
Haven't tested, but I'd assume that this would do the trick:
//Assuming ol = Dynamicweb.eCommerce.Orders.OrderLine
BR.
Lars
I already tested that and it does nothing :(.
Got any other ideas?
/Magnus
Could you show your code? I want to check it. Thanks.
var pr = new Dynamicweb.eCommerce.Prices.PriceInfo();
pr.PriceWithoutVAT = 100;
ol.SetUnitPrice(pr);
ol.Save();order.Save();
Dynamicweb.eCommerce.Common.Context.SetCart(order);
All this is done in the [Subscribe(Dynamicweb.Ecom7.Cart.Notifications.BeforeRenderingNewStep)] notificationsunscriber. And now I am calculating the price withous vat and the just using the SetUnitPrice(double Price), but I have to do another postback to get the changes to take affect in the frontend. Maybe I am using the wrong notificationSubcriber?
/Magnus
I found this to be working for me:
[Subscribe(Dynamicweb.Notifications.eCommerce.Cart.Line.Added)]
public class test : Dynamicweb.Extensibility.NotificationSubscriber
{
public override void OnNotify(string notification, object[] args)
{
var test = (Dynamicweb.eCommerce.Orders.OrderLine)args[3];
test.SetUnitPrice(15);
}
}
Even though I'm using Cart V2, this ancient ancient notification apparantly still works. In this example VAT is calculated afterwards, so this results in a total price of 18,75 for this order line.
Apparantly this happens after the page cart is rendered. On page load the page cart displays the original order line price, but when refreshing the page, the new price is being used.
BR.
Lars
I found, that accessing the price on the order updates the price, and combined with a shaking the cart, I could get it working ..
Case :
I did some calculations and updated the unitprice, but found that the total of the order would not get updated til second time around, eg.
Orderline price = 100
Order total = 200
Until I added these little suckers (In an orderlinetemplateextender):
Dynamicweb.eCommerce.Common.Context.SetCart(Order);
var x = Order.Price.Price;
You must be logged in to post in the forum