You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When updating a cart, the line item is expected to update based on the id provided in the payload. However, the update fails because the code appears to use the array index instead of the provided id, preventing the correct line item from being updated.
Steps to reproduce
Send a request to update the cart with the following JSON payload:
{
"lineItems": [{
"id": 129,
"qty": 10
}]
}
Check the cart to see if the line item with id 129 has been updated.
Expected behavior
The cart should update the line item with the provided id (in this case, 129), so that the line item reflects the new quantity. In this case, the updated line item should show a quantity of 10.
Actual behavior
The cart message says cart updated but the line item is not updated.
I dug through the code a bit I see that it attempts to use the array index (0) as the line item ID instead of using the id field (129) from the line item object, causing the wrong item to be fetched or no item to be found.
What happened?
Description
When updating a cart, the line item is expected to update based on the
id
provided in the payload. However, the update fails because the code appears to use the array index instead of the providedid
, preventing the correct line item from being updated.Steps to reproduce
Expected behavior
The cart should update the line item with the provided id (in this case, 129), so that the line item reflects the new quantity. In this case, the updated line item should show a quantity of 10.
Actual behavior
The cart message says cart updated but the line item is not updated.
I dug through the code a bit I see that it attempts to use the array index (0) as the line item ID instead of using the
id
field (129) from the line item object, causing the wrong item to be fetched or no item to be found.commerce/src/controllers/CartController.php
Lines 245 to 246 in 75832ab
if I send the line Items as an object of key (id) /value (lineItem) pairs like the code expects it seems to work
However the documentation states
I'm not sure if it's the expected behaviour and the documentation is incorrect (or I misunderstood it) or it's actually a bug.
Craft CMS version
Craft Pro 5.6.4
Craft Commerce version
5.3.1
PHP version
8.3.14
Operating system and version
Darwin 24.3.0
Database type and version
MySQL 8.4.4
Image driver and version
Imagick 3.7.0 (ImageMagick 7.1.1-41)
Installed plugins and versions
The text was updated successfully, but these errors were encountered: