Hi guys,
THis is URGENT, Appreciate your understanding!
I need to be able to add a custom discount orderLine to OrderObject. I must do that After order is complete.
Why you might ask? My collegue already tried changing Cart object in the OnOrderLineAdded event, and so far BEFORE order hits payment gateway - solutions seems to do exactly what we need.
But as soon as Cart becomes Order, it ignoves a custom discount orderline that was added.
That is why the easyest way out would be ofcourse to manipulate order object after it passed paymeng gateway, but before it is saved in the db, etc... that would be ideal.
Here is my example so far:
double quantityDiscountAmount = RemoteService.CalculateDiscount(); // Getting SpecialDiscount from ERP order.AllowOverridePrices = true; var name = string.Format("ERP-Discount-{0}", order.ID); B2BLogging.CreateDiscountOrderline("Creating new and setting"); var discountOrderline = new OrderLine(); discountOrderline.Order = order; discountOrderline.Quantity = 1; discountOrderline.ProductName = name; discountOrderline.SetOrderLineType(OrderLine.OrderLineType.Discount); discountOrderline.AllowOverridePrices = true; discountOrderline.SetUnitPrice(Base.ChkDouble(quantityDiscountAmount)); discountOrderline.Price.PriceWithoutVAT = Base.ChkDouble(quantityDiscountAmount); discountOrderline.Price.PriceWithVAT = Base.ChkDouble(quantityDiscountAmount); order.OrderLines.Add(discountOrderline); discountOrderline.Save(); discountOrderline.ClearCachedPrices(); order.AllowOverridePrices = true; order.ClearCachedPrices(); order.Save();
After order is done, Orderline is added in order overview, with correct price, but total price is not including the discount.
This code works really nicely while in Cart.
I also tried this order DowngradeToCart() and UpdateCartToOrder() again. But this did not help either.
This is the result. https://www.screencast.com/t/Ct5e6Rtz7jKR
Line is added, but line price is not calculated along in total.
/Dmitrij