Skip to content

Fix cart line attributes being dropped and userErrors not logged - #372

Merged
ryanmitchell merged 1 commit into
statamic-rad-pack:mainfrom
lwekuiper:fix/cart-line-attributes
Sep 22, 2026
Merged

ryanmitchell merged 1 commit into
statamic-rad-pack:mainfrom
lwekuiper:fix/cart-line-attributes

Conversation

@lwekuiper

Copy link
Copy Markdown
Contributor

Two small bugs in the cart JS, both in the same add-to-cart path.

updateFromResponse() builds the line item attributes with attrs[key] = attr.value, but key is never defined in that scope. Under a bundler this throws a ReferenceError in strict mode, and otherwise it writes to a global, so line attributes never reach $store['statamic.shopify.cart'].lineItems. This is what you get back from cartLinesAdd when you pass attributes, so any custom line data (we use it for shirt name and number personalisation) is lost when the cart re-renders.

- line.attributes.forEach((attr) => attrs[key] = attr.value);
+ line.attributes.forEach((attr) => attrs[attr.key] = attr.value);

The second one is in addLines(): the userErrors branch logs errors from the destructured response instead of the user errors it just checked, so the warning is always empty at the point where it would be most useful.

  if (data.cartLinesAdd.userErrors.length > 0) {
-     console.warn(errors);
+     console.warn(data.cartLinesAdd.userErrors);

Both are in the published JS, so they only reach apps after a re-publish.

@ryanmitchell

Copy link
Copy Markdown
Contributor

Good spot, thank you for both.

@ryanmitchell
ryanmitchell merged commit d70d303 into statamic-rad-pack:main Sep 22, 2026
@lwekuiper
lwekuiper deleted the fix/cart-line-attributes branch September 22, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants