Cart API is acting weird #491
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@studiodrimmel You're updating the cart item by changing the product ID and expecting it to reset the product name and price, but the API does not implement that behavior currently. One can argue that the design should be different, and that is probably a good point - but it's not broken. Array merging the way it works now has caused significant confusion for devs and we might change it in the future with API versioning. The ideal way to add a new item to the cart is by doing Array elements get merged in a PUT request by matching |
Beta Was this translation helpful? Give feedback.
@studiodrimmel You're updating the cart item by changing the product ID and expecting it to reset the product name and price, but the API does not implement that behavior currently.
One can argue that the design should be different, and that is probably a good point - but it's not broken. Array merging the way it works now has caused significant confusion for devs and we might change it in the future with API versioning.
The ideal way to add a new item to the cart is by doing
POST /carts/{id}/items
, which adds an element to the items array. That's what Swell.js does when you callswell.cart.addItem()
.Array elements get merged in a PUT request by matching
id
field (if one exists on the mo…