Repository navigation
fix(shop): the cart refuses quantities it can't fulfil (#215) - #224
Merged
Merged
Conversation
POST /api/shop/cart never read inventory, and PATCH only capped at 999, so an out-of-stock variant could be added and any line raised past stock — via curl, a stale tab, or a line that was in stock when added. The customer paid first and the merchant found the shortfall after. CartService.addItem and setQuantity now check the line's FINAL quantity against sellableQuantity() — the same rules checkout's reservation uses: on_hand - reserved at the default location; untracked, continue- selling and row-less variants unlimited; a bundle limited by its scarcest component. Checking the final quantity (not the amount added) closes the "+1 five times" bypass in the downstream bactrack fix. Lowering a line is always allowed. The API answers 409 OUT_OF_STOCK with `available`; the product and cart pages show "Only N in stock" / "Sold out" in the visitor's language instead of the server's English. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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 #215.
Bug
POST /api/shop/cartnever read inventory;PATCHonly capped at 999. Out-of-stock variants could be added and lines raised past stock (curl, stale tab, or a line in stock when added). The customer paid first and the merchant discovered the shortfall later.Fix
CartService.addItem/setQuantitycheck the line's final quantity against newsellableQuantity()(bundles.ts). It uses the same rules as checkout's reservation:on_hand - reservedatdefault; untracked / continue-selling / row-less are unlimited; a bundle is limited by its scarcest component.409 OUT_OF_STOCKwithavailable(+cartItemId); other cart errors unchanged (400).Only N in stock/Sold outin the visitor's language. The cart page used to swallow PATCH failures silently.Unlike bactrack's version, this respects continue selling when out of stock (pre-orders) and checks bundles.
Tests
6 integration tests through
CartService+ real migrations: sold out; +1×N bypass; other shoppers' reservations; raise refused / lower allowed; untracked and continue-selling unlimited; bundle by scarcest component.Gate: lint 0 errors · check 0 · 1157 tests on this branch alone, merged with main's #223 as well · build · contract-guard · css-inventory +0.
🤖 Generated with Claude Code