Hi there,
I have a solution that contains code like this:
OrderLineViewModel cartItem = new OrderLineViewModel(); cartItem.ProductId = prodId; cartItem.ProductLanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID; cartItem.ProductVariantId = ""; cartItem.Quantity = Dynamicweb.Core.Converter.ToDouble(productQuantity); cartItem.OrderLineFields = SaveOrderLineFields(); if(productUnitId != "") { cartItem.UnitId = productUnitId; } var newOrderLine = CartService.CreateCartLineFromModel(cart, cartItem); if (newOrderLine != null) { cart.OrderLines.Add(newOrderLine); } Services.OrderLines.Save(cart.Id, cart.OrderLines); SaveCartChanges(cart);
(I think that whoever wrote it copied it from CartController.AddLineToCart as it looks pretty similar.)
We found that with this code, no LineAdded notification is being called but I am not sure why.
In CartService.CreateCartLineFromModel I see this
orderLine.Id = string.Empty;
Then in: CartService.NotifyOrderlinesAdded
// If the ID isn't set, then the orderline is merged - not added
if (!string.IsNullOrEmpty(newOrderLine.Id))
{
NotifyCartLineAdded(newOrderLine, cart, pageView);
}
However, I am calling Services.OrderLines.Save(cart.Id, cart.OrderLines) which should give them an ID at that point, no?
What's the proper way to add an order line and still have LineAdded raised? We're on DW9.
Thanks!
Imar