Developer forum

Forum » Development » Adding new orderlines to cart using dwapi

Adding new orderlines to cart using dwapi

Pedro Meias
Pedro Meias
Reply

Hello,

Dynamicweb 9.15.3

We are adding products to a cart using the following dwapi endpoint - (POST)/dwapi/ecommerce/carts/{secret}/items

When we add a product that already exists in Cart, instead of incrementing the existing orderline quantity, a new orderline is being added. Is this the expected behaviour? should we validate first if product is in cart and use a different endpoint?

Example request body we are submitting to the API

How cart looks in backend

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Yes, that is expected behavior.

POST means create new - if you want to update an existing one, use PATCH endpoint.

PATCH /dwapi/ecommerce/carts/{secret}/items/{itemId}

I am not sure how you do the implementation, but usually you would have a cart object in JS with the cartlines and make the decission there.

We could add a "CreateOrUpdate" endpoint or add a parameter to the POST endpoint so it can merge if product is the same.

BR Nicolai

Votes for this answer: 1
 
Pedro Meias
Pedro Meias
Reply

Hi Nicolai,

Thank you for the explanation. We are trying to do a bulk import for one of our customers.

1 - User uploads an excel file
2 - We validate if the products exist or are out of stock

3 - Add valid products to cart 

If you can make it have a similar behavior as when we add a product to cart in frontend (if the product is already there - merge), that would help us a lot.

 

Thank you.

 

You must be logged in to post in the forum