Developer forum

Forum » Ecommerce - Standard features » Multiple orderlines for same product

Multiple orderlines for same product

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

We are working on a shop that sells contact lenses. The nature of selling contact lences, is that you often sell them in pairs (pairs of packages), where the configuration of each of the pairs wilw typically be different. See attachment for a typical add to cart scenarie for Contact Lenses.

The properties for Contact lenses ara:

  • Strength (Styrke)
  • BasisCurve (Basiskurve)
  • Diameter
  • Cylinder
  • Axis
     

Now lets say we have a scenarie, where a costumer buys 1 pair of contact lenses with different configurations - jusst as shown in the attachment.

 

When they get added to cart,  I want them to be created as different orderlines


I have created Custom Orderline fields called CustomStrength, CustomAxis, CustomCylinder and CustomEye (To apply the right or left value)
 

Is it possible to create the left and the right as two differnt oderlines? If so, how can this be done?

 

/Hans

 

 

 

 

Skærmbillede_2021-02-25_kl._11.16.16.png

Replies

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Hans,

The way I would do it would be to use a combination of AddMulti and OrderlineFields.
Meaning that in your screen, each column would be a product (same productId and product number) but with its own OrderlineFieldValues.
And the "Add to cart" button would be in fact a multi-add button.

I understand this is very generic definition but this is how I would do it.

I hope it helps.

Adrian

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi Adrian

 

Thank you. I have tried that, but somehow - the orderlines don´t get added when I add to cart. 

I have made sure that the OrderLineFields are attached to the shop, and inherited to the ProductGroup.

I am calling this async like this.

 data.append('CartCmd', 'AddMulti');
 data.append('ProductLoopCounter1', '1');
 data.append('productid1', varprodid);
 data.append('EcomOrderLineFieldInput_CustomStrength1', strengthLeft );
 data.append('EcomOrderLineFieldInput_CustomCylinder1', cylinderLeft );
 data.append('EcomOrderLineFieldInput_CustomAxis1', axisLeft );
 data.append('Quantity1', amountLeft);

 data.append('ProductLoopCounter2', '2');
 data.append('productid2', varprodid);
 data.append('EcomOrderLineFieldInput_CustomStrength2', strengthRight );
 data.append('EcomOrderLineFieldInput_CustomCylinder2', cylinderRight );
 data.append('EcomOrderLineFieldInput_CustomAxis2', axisRight );
 data.append('Quantity2', amountRight);
 
 
 
 
 
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://mywebsite.com', true);
xhr.onload = function () {
 console.log(this.responseText);
};
xhr.send(data);

Offcourse, strengthLeft, cylinderLeft ... are variables containing the values.

Does this look correct, or am I missing something?

 

/Hans

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Hans,

I am not 100% sure but the AddMulti might not work with POST. It might work only with GET.

Again, I might be wrong about it.

Other than that, the properties seem fine the way you have defined them.

Adrian

 

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

 

I actually got it to work using POST. Using GET does not anything to cart.

 

However, I can´t get it to work adding the same product to two different orderlines. Its getting treated as the same orderline. How do i "Start a new orderline" in a single request.

 

/Hans

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Got it to work using the XMLHttpRequest explained above, and using POST

 

if in doubt - please feel free to ask

 

/Hans

 

 

You must be logged in to post in the forum