feat(examples): add several products to the cart in one atomic request - #645
Merged
Merged
Conversation
…n core The search page's two-column grid had no breakpoint, so at phone width the results column ran off the right edge of the viewport.
…t from search results Search result cards get a checkbox, and one action adds every selected product in a single Cart API request with options.add_all_or_nothing set to true. If the cart refuses any product, it takes none, and the shopper is told which product was refused and why. A family card is selectable once its options resolve to a child product, which is what gets added. Bundles and incomplete families are disabled with the reason shown. The selection clears on any change to the results. Closes #534
…atch A server error or an empty error body does not prove the cart is unchanged, so the shopper is asked to check the cart instead. A successful add now clears only the cards it sent, so a card ticked while the request was in flight stays selected. The README names Catalog Search as a requirement.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #534.
Search results in
examples/coreget a checkbox on each card. One action adds every selected product in a singlemanageCartscall with aBulkAddItemsRequestbody andoptions.add_all_or_nothing: trueset explicitly. If the cart refuses any product, it takes none of them.The lesson is atomicity, not batching. A browser loop of single adds leaves a half-filled cart when item 3 of 4 fails.
What can be selected
selectedVariantfromresolveCardState). The cart rejects a parent product with 422 "is a base product", which was confirmed live.aria-describedby.Bundles are not this feature. A bundle is one cart line holding a pre-authored configuration. The README says so.
The checkbox sits outside the card's
LocaleLink, so clicking it never navigates. Its label carries the product name for screen readers.Decisions
revalidateTag("cart")in the action, and invalidation of the cart query. A failure shows inline in the bar instead of as a toast, because it lists products.Failure message, from a live check (integration store, guest cart)
errorsentry per refused product. Each entry carriesmeta.id, which the generatedResponseErrorItemtype declares. Reading back the cart showed it unchanged every time.title, for example "Insufficient stock".add_all_or_nothing: falsethe cart answers 201 withdata,errorsandmeta, and adds the valid line. The 201 type has noerrorsfield, which is why partial adds stay out of scope.Also in this PR
f92a7fe0: the search page'sgrid-cols-[1fr_3fr]had no breakpoint, so at phone width the results column ran off-screen. It now stacks belowmd. This is a separate commit and is pre-existing onmain.Checks
vitest runpasses: 152 tests, 28 of them new, inbulk-selection.test.tsandbulk-add-to-cart.test.ts.tsc --noEmitis clean.next buildsucceeds.next start.Screenshots
1. Checkboxes, with incomplete families and a bundle disabled
2. Four selected, including a resolved variant (Green T-Shirt, lg), with the action enabled
3. The cart after the add, showing all four
4. A rejected batch
An out-of-stock variant is refused:
A product the cart cannot add is refused. Digital Test was valid and was not added either:
The cart afterwards is unchanged: the same four lines and the same total.
5. Nothing selected, with the action disabled (just after a successful add)
6. Phone width