Hello:
I have a issue with my webpage cart review. In our webpage all the products have aditional services like for example additional guarantee (if i bought the same wash machine 3 times i have to be able to choose aditional services for every one wash machines) .
My first idea is split every order line that have quantity greater than 1 into n orderlines with quantity 1.
So i made a Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.Line.Increased that split all order lines greather that 1 into n orderlines. It works well but this notification is executed 3 times before cart is being show to the user and it create more orderlines that the user says. I dont know why this happend, maybe is because the cart context, im not sure.
For example if i change a order line from 1 quantity to 3, my notification generates 6 order lines (1+2+2+2) . Here is a snapshot:
Here is the code of my increased notification:
[Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.Line.Increased)]
public class EcomCartLineDecreasedObserver : Dynamicweb.Extensibility.Notifications.NotificationSubscriber
{
public override void OnNotify(string notification, Dynamicweb.Extensibility.Notifications.NotificationArgs args)
{
if (args == null || !(args is Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.Line.IncreasedArgs))
return;
Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.Line.IncreasedArgs item = (Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.Line.IncreasedArgs)args;
OrderLineService orderLineService = new OrderLineService();
int amountIncreased = (int)item.AmountIncreased;
item.IncreasedLine.Quantity = 1;
for (int i= 0; i < amountIncreased; i++)
{
OrderLine ol= orderLineService.Create(item.Cart, item.IncreasedLine.Product, 1, new Dynamicweb.Ecommerce.Stocks.StockUnit(), item.IncreasedLine.UnitPrice);
ol.OrderLineFieldValues = item.IncreasedLine.OrderLineFieldValues;
ol.OrderLineFieldValues.First(v => v.OrderLineFieldSystemName.Equals("Retirada")).Value = "NO";
ol.OrderLineFieldValues.First(v => v.OrderLineFieldSystemName.Equals("Garantia")).Value = "NO";
}
Dynamicweb.Ecommerce.Common.Context.SetCart(item.Cart);
}
}
Best Regards,
Jose.