Posted on 29/08/2019 09:11:39
Hi,
I am trying to add Order lines to a cart for non existing product. I can see that it creates an order in backend but in frontend if i refresh the cart page it seems like it removes the order line from a cart if product doesn't exist and after that order in backend also gets updated and order line gets removed from there as well.
Is this the intended behavious or i am doing something wrong in the code?
OrderService orderService = new OrderService();
OrderLineService orderLineService = new OrderLineService();
ShopService shopService = new ShopService();
var area = Dynamicweb.Services.Areas.GetArea(1);
OrderContext context = OrderContext.GetOrderContextById("ORDERCONTEXT5");
Dynamicweb.Ecommerce.Common.Context.CartContext = context;
var cart = Dynamicweb.Ecommerce.Common.Context.Cart;
if(cart == null)
{
cart = new Order()
{
IsCart = true,
LanguageId = area.EcomLanguageId,
OrderContextId = context.Id,
ShopId = area.EcomShopId,
ShopName = shop.Name
};
Dynamicweb.Ecommerce.Common.Context.SetCart(cart);
}
var OrderlineBuilder = new OrderLineBuilderConfig()
{
ProductId = string.Empty,
Quantity = 1,
VariantId = string.Empty,
VariantText = string.Empty,
UnitId = string.Empty,
OrderLineType = OrderLineType.Product,
ReferenceUrl = string.Empty,
PageId = 2235,
ProductName = product.Name,
ProductNumber = string.Empty,
};
OrderLine ol = orderLineService.OrderLineBuilder(cart, OrderlineBuilder);
orderLineService.SetUnitPrice(ol, 100);
orderLineService.Save(ol);
orderService.Save(cart);
Dynamicweb.Ecommerce.Common.Context.SetCart(cart);