I am trying to edit an order that have been giving up.
This order may has a product that I want to swap with an other product. Since there are some unique identifier, its kind of complicated now to tell what item you want to delete. How ever, I am currently getting the lineItems from the order, searching the payloads for the product number and and if I found it, I take the unique id and delete the product.
So fine so fare...
Now I want to add a new product (that actually exists in the SWDB). Goal is, to pass only the required informations to the API to add that product to the order.
For some reason I can't find anything about this in the internet or I am very bad at searching. How ever, my tests failed all and currently I was'nt able to deal with this (what I actually consider as common needed action) problem, adding a product.
As I sayed, the documentation does'nt seem to provide me with enough information to do so. Am I the only one who want to add a product via api? I strongly guess not :D
So does anyone can hint me in the right direction?
I finaly made it and add my experience here to help others may having the same issue.
Steps in order to go:
Description
To add a product to an existing order basically have to call the endpoint
As body you have to pass at least the quantity
CAUTION: In order to do this, you HAVE to create a version of the order.
You can do this with
This will return an array with a version number
versionIdand some other fields.You have to add this
versionIdto your headerbefore sending any updates to the sw order.
Now you can do your edit.
When you are done with them edits, you have to merge the order version into your actuall order. You can do this by running this endpoint
After merge, shopware calls a recalculation to have the price calculated correctly.
I hope this helped.
Helpfull information
If you look into your browsers console, you actually can see every api call in the network tab. So you can perform an action in the admin section and look what happend in the network tab to build your stuff.