#How to add multiple line items to cart
11 messages · Page 1 of 1 (latest)
You can attach some unique property to the lineItem metadata
medusa will then treat it as unique
I don't understand what you mean
Can anyone help me with this issue?
Why do you need it? What is your use case?
While adding a product A in cart, I need to add two more products B and C as it's add-on.
There's nothing in medusa built-in for it. You would need to loop through your variants and add them.
const variantsToAdd = [{variant_id: 'variantA', quantity: 1},{variant_id: 'variantB', quantity: 1},{variant_id: 'variantC', quantity: 1}];
Sequentially:
for (const variant of variantsToAdd) {
await medusaClient.lineItems.create(cartId, { variant_id: variant.variant_id, quantity: variant.quantity});
}
In parallel
await Promise.all(variantsToAdd.map((variant) =>
medusaClient.lineItems.create(cartId, { variant_id: variant.variant_id, quantity: variant.quantity});
));
Not sure about 409 conflicts when doing parallel, try.
ok let me try
We created a new endpoint for this -> Much more efficient