Repository navigation
Carry shopper product customization through add-to-cart - #1534
ajaynes-godaddy wants to merge 4 commits into
Conversation
AIROBUILD-9325
AddToCartItemInput was narrowed to { skuId, name, quantity }, so shopper
customization (uploaded designs, add-ons, metafields) never reached
order-api or checkout. Widen the cart contract end-to-end:
- order-subgraph.ts: add optional details (productAssetUrl,
selectedAddons) and metafields to AddToCartItemInput, forward them in
buildAddLineItemBySkuIdInput with length/HTTPS/count validation, and
select metafields in getCartOrderQuery so they round-trip on read.
- cart/[id]/items/POST.ts: forward the full validated body instead of a
hand-picked three-field literal.
- cart-model.ts: widen the storefront-side AddToCartItemInput identically.
- commerce-provider.tsx: addItem() was rebuilding a narrowed
{ skuId, name, quantity } object before calling addToCart(), dropping
details/metafields even after the type widened; pass the full item
through instead.
🦋 Changeset detectedLatest commit: b014094 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks Drew, this is a nice, small change and the contract matches order-api's Worth fixing
Smaller items
What I checked
Could you also add screenshot proof from the MCP playground showing a customized item in hosted checkout (the add-on text and the preview image)? Thanks! |
@sbolinger-godaddy Here's a short Loom showing the line item data before and after: https://www.loom.com/share/0e97ef9539b4401bb1290b648785bd0c I'll get you a catalog add-to-cart view version of this and report back. Edit: Here's another short loom showing the product detail and image (the mug): https://www.loom.com/share/2a72b573652f457b9f5442df1051cfa9 Let me know if you had something else in mind. |
The cart drawer mapped only catalog selectedOptions (Color, Size) into CartItemOptions, so a line's selectedAddons (shopper customization) showed the preview image but not the add-on text, leaving the drawer out of sync with checkout. Fold selectedAddons into the same options list useCart() already exposes, reusing the existing "Label: value" rendering.
… cart
assertValidCartItemInput ran inside buildAddLineItemBySkuIdInput, which on
POST /cart is only reached after addDraftOrder already created the cart —
an invalid productAssetUrl or an oversized add-on list orphaned that cart
and, since it threw a plain Error, came back as a 500 instead of a 400.
Run the same validation in the pre-create loop, and switch every check to
InvalidRequestError so it maps to 400.
Also reject a LIST-option addon value ({ optionValueId }) explicitly: only
TEXT/NUMBER options ({ inputValue }) are supported by this change, and an
optionValueId-only value previously crashed with a TypeError on
.inputValue.length instead of a clean validation error.
Correct a comment that called this guard UX-only with order-api's schema
as the authoritative enforcement point — order-api's schema has no such
length/HTTPS/count limits, so this is the only place they're enforced.
|
@sbolinger-godaddy I believe I've addressed all of your feedback in 454ab95 and b014094. |
Summary
Add-to-cart calls can now carry an optional
detailsobject (a product asset URL and selected add-ons) andmetafieldsalongside the existingskuId/name/quantityfields, so a shopper's product customization travels with the line item all the way through checkout instead of being limited to the client. Existing add-to-cart calls that don't use these fields are unaffected.Changeset
Test Plan
Setup
No special setup required — standard local dev environment.
Steps
Run the following:
pnpm --filter @godaddy/gd-commerce-server testdetails/metafieldsreach theaddLineItemBySkuIdmutation and that an invalidproductAssetUrlor an oversized add-on list is rejectedRun the following:
addItem()call forwardsdetails/metafieldsunchanged in the cart POST bodyNote:
colors.test.tsandartifacts.test.tscurrently fail locally withlocalStorage.clear is not a function— this is a pre-existing environment issue unrelated to this change (reproduces identically onmain) and does not affect the 179 other tests, including the new one above.Confirm CI checks pass