Short answer: no.
commercetools offers some #update-actions">update actions on the Order itself, but none of them helps you in case you want to change the Order price.
And that’s the reason why we will use Order Edits.
As per the commercetools official documentation, here’s the Order Edits definition:
OrderEdit are containers for financial changes after an Order has been placed.
If no financial aspect of an Order should be changed, use #update-order">Update Order, which does not perform a recalculation. If no Deliveries or Payments occurred, you can alternatively #replicate-cart">replicate the Order as a new Cart.
commercetools Order Edits documentation
Imagine the following scenario:
The simplest strategy is to apply a #directdiscount">Direct Discount.
A Direct Discount represents a CartDiscount that is only associated with a single Cart or Order.
In this code we specify:
We obtain a JSON representing the newly created OrderEdit.
The JSON is easy to read.
What’s important is to keep the OrderEdit ID and the OrderEdit version for the next call.
The OrderEdit type should be set to PreviewSuccess.
We can now apply the OrderEdit:
We will just pass the OrderEdit ID in the URL, and the OrderEdit version plus the Order version in the body.
That’s it!
In the result you should see an important result section like this:
"result": {
"type": "Applied",
"appliedAt": "2024-05-03T11:09:08.051Z"
[...]
sto confirm that it’s applied.
The result section also reports the previous and current state of the OrderEdit resource, respectively in the excerptBeforeEdit and excerptAfterEdit section:
"excerptBeforeEdit": {
"totalPrice": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 209790,
"fractionDigits": 2
},
[...]
},
"excerptAfterEdit": {
"totalPrice": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 201690,
"fractionDigits": 2
},
[...]
}
And that’s it.
The post Unlocking commercetools: Modifying Order Prices Made Simple appeared first on L.S..
Ancora nessun commento. Sii il primo!
Accedi per votare e commentare!