Developer forum

Forum » Development » Split and merge orderlines from api

Split and merge orderlines from api

Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Hi,

As mentioned in the thread https://doc.dynamicweb.com/forum/development/development-split-orderlines-in-cart, I need to be able to split and merge orderlines in the cart.

Does the built-in functionality with merging similar orderlines also work when adding orderlines from the api?

I've tried to split an orderline, by cloning the original and changing the quantity, before saving. I'm having trouble merging them back together though.

--
Best regards
Kurt Moskjaer Andersen


Replies

 
Nicolai Pedersen
Reply

Merging does not occur when you use the api.

I am not sure you can split an orderline and only change quantity. The only thing merge do, is deleting the orderline that should not be there and in some cases sum the quantity of the deleted orderline and the orderline that is left behind. So merge is basically 2 completely similar orderlines, one is deleted and quantity is updated to the sum of the 2.

Maybe tell what you are trying to achieve (not code wise, but functionality wise) - why are you doing this? We might be able to point in the right direction.

If you have code, feel free to post it.

BR Nicolai

 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Hi Nicolai,

Thank you for your response.

I would like to be able to offer partial delivery for an order.

If a customer requests 1000 pcs. of a product, but there is only 550 pcs. in stock, I need to split the orderline. The initial orderline would then hold the 550 pcs. with immediate delivery, while the second orderline holds the rest 450 pcs., with delivery later.

If the customer wants total delivery, the orderlines should be merged (if partial delivery was first choosen), to hold the total 1000 pcs. with delivery when the total quantity is on stock.

I hope it makes sense :)

I've already made a notificationsubscriber on Order.Values.Saved, to create the second orderline, but I'm having problems merging them again, when total delivery is selected. At first everything merges fine, but if the customer reloads the cart-page by pressing the F5-key, the merge seems to be done once again.

--
Best regards
Kurt

 
Nicolai Pedersen
Reply

ok, then you need to set a custom orderline field value when you split the orderlines into 2. Maybe with "delivernow" value on one of them or something. In this way the orderlines will be seen as 2 different ones.

BR Nicolai

 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Yes, and that's working just fine. I've done this by cloning the original orderline and changing the quantity and a custom orderline field.

When merging the two orderlines, the way to go, is manually change the total quantity of the original orderline and delete the second orderline, right?

--
Best regards
Kurt

 
Nicolai Pedersen
Reply

Exactly!

 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

But when you say I should add a custom orderline field value, in order for DW to distinguish the two orderlines, it seems there would be some kind of automatic merge in the cart after all?

/Kurt

 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Actually, if my original orderline has the quantity of 550 and I add a second orderline with quantity 450 pcs. and add some custom order field values, the carts shows two orderlines, with a total of 1000 pcs.

If I afterwards remove all custom order field values on all orderlines, so the orderlines should be similar (besides quantity), the two orderlines are automatically merged into one orderline, but the resulting quantity is incorrect. In this example, the resulting quantity is "1100,900" and not "1000" ?

/Kurt

 

 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

I've managed to resolve the problem.

This issue was related to cloning the original orderline and the order in which I deleted the second orderline and saving the whole order.

BR Kurt

 
Nicolai Pedersen
Reply

Glad you nailed it and thanks for telling.

Maybe you have some code to share?

Thanks, Nicolai

 

You must be logged in to post in the forum