Developer forum

Forum » Development » Divide order line Quantity issue

Divide order line Quantity issue

Jose Caudevilla
Reply

 

 

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.

 

Replies

 
Adrian Ursu
Adrian Ursu
Reply

Hi Jose,

It might be easier if you use an Orderline Field.

If your Orderline fields have different values, they will be kept as separate Orderlines in the cart.

I hope this helps.

Adrian

 
Jose Caudevilla
Reply

Hi Adrian,

Thanks you're right,

But im not sure when i have to set this different value.

For example i created a NLine orderField to set the number of the unit product.

Do you think i have to use Ecommerce.Cart.Line.Increased when and set the different values?

I still having the same problem.

Jose.

 
Adrian Ursu
Adrian Ursu
Reply
This post has been marked as an answer

Hi Jose,

I don't think you need to add custom logic.

You can supply a different value in that field from the moment you add to the cart.

Even if it's not the final value that you expect and if you plan on editing it later, for the purpose of keeping the orderlines separate, you just need to make sure you have a unique value in that field. Like a timestamp or a random key. And later on (in the cart) you can edit it.

Of course, if it's possible, you can ask the user to select a value before adding to cart. But I expect (for usability purposes) to allow editing of that option (or options) in the cart as well  (if the user changes his mind).

With the built-in logic, if you increase the quantity of an orderline, it will not affect the other orderlines.

 

I hope this helps.

Adrian

Votes for this answer: 1
 
Jose Caudevilla
Reply

It works!

 

Thanks Adrian

 
Adrian Ursu
Adrian Ursu
Reply

Hi Jose,

I am glad it worked.

You are welcome!

Adrian

 

You must be logged in to post in the forum