Developer forum

Forum » Ecommerce - Standard features » Using dwapi/ecommerce/carts/ to create and manipulate carts

Using dwapi/ecommerce/carts/ to create and manipulate carts

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I've seen a lot of buzz around this new API and I was thinking about trying my hand with it.

I have a case where I have to add some products to the cart and based on some decisions, I need to create an additional orderline that is related to the first one.

Also, there are 2 other constraints:

1. I have to be able to add multiple orderlines at once

2. I have to add OrderlineFields

3. I might have multiple orderlines with the same ProductID

Which endpoints I should use for these purposes?

From the Swagger I am not able to see the structure of the payload for adding the Items to cart.

I also see that I can edit an orderline based on the itemid which in my case can be present on multiple orderlines. Unless I am not mistaking "itemid" for the orderlineid

Thank you for any suggestions and I apologize if my questions are too lame :)

Thank you,
Adrian

 


Replies

 
Nicolai Pedersen
Reply

Hi Adrian

It is an API based approach so things are bit more handheld.

The command on a cart or orderlines are like this:

  • POST: Create
  • PATCH: Update
  • GET: Read
  • DELETE: Delete

So to create 2 orderlines, you create an orderlineviewmodel (see below) and post it to the endpoint using the cart secreet.

You can explore that payload as the schema on the request body - you can find that in the swagger doc as well:

So you can just post something like this:

{
ProductId:"prod1",
ProductVariantId:"vo1.vo2",
Quantity:2
}

If you create 2 POSTs using the same productid, you will get 2 orderlines. It is very explicit. You might get an additional parameter in a future version where you can add merge=true so we handle the merge using the rules you know from cartcmd=add

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for the guidance.

I will explore it further.

Thank you,
Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

One more question. If I want to create a discount Orderline, can I use the API?

Can I set the parent OrderlineID that the discount is attached to?

And most important, will the cart keep the OrderlineDiscount that I create via API or it will delete it?

Thank you,
Adrian

 

You must be logged in to post in the forum