Posted on 18/04/2019 19:19:34
This is the code I am using from the above 'inspiration'. However, SetUnitPrice() does not appear to do anything. The price isn't being set when that function call is made so I get the products added to the cart, but they all have price of $0.00.
I'm at a loss here.
var Cart = Dynamicweb.eCommerce.Common.Context.Cart ?? new Order();
Cart.Save();
foreach (var quoteLineItem in quoteLines)
{
if (string.IsNullOrWhiteSpace(quoteLineItem.ConfigID__c))
{
continue;
}
GuruConfiguration gcon = new GuruConfiguration();
GuruConfigurationRepository gcrepo = new GuruConfigurationRepository();
gcon = gcrepo.GetById(quoteLineItem.ConfigID__c);
var guru = GuruHelpers.ConvertCudToFlatObjects(quoteLineItem.CUD_XML__c);
var data = Boxx.Web.Shared.Guru.GuruExtensions.GetOrderDataFromCud(quoteLineItem.CUD_XML__c);
var line = new OrderLine();
line.Product = null;
line.ProductID = gcon.DynamicwebProductId;
Product thisProduct = Product.GetProductByID(line.ProductID);
line.ProductNumber = thisProduct.Number;
line.ProductName = thisProduct.Name;
line.Quantity = quoteLineItem.Quantity > 0 ? (double)quoteLineItem.Quantity : 0;
line.AllowOverridePrices = true;
if (data.SystemDiscountPrice == 0)
{
line.SetUnitPrice(data.SystemTotalPrice);
}
else
{
line.SetUnitPrice(data.SystemDiscountPrice);
}
line.SetOrderLineType(OrderLine.OrderLineType.Fixed);
line.Order = Cart;
Cart.OrderLines.Add(line);
Cart.ClearCachedPrices();
Cart.Save();
}
Dynamicweb.eCommerce.Common.Context.SetCart(Cart);