example: don't add out-of-stock variants to the cart - #148
Merged
Conversation
The cart tab added `product.productVariants.first` regardless of whether that variant could be bought. Shopify creates a line for an unavailable variant with quantity 0 and reports no userErrors, so on stores whose first variant is out of stock every add showed up as a "0x" line and the +/- buttons looked dead — the server clamped the quantity back to 0. Pick the first variant with availableForSale == true instead, mark out-of-stock products and lines in the UI, and report it when Shopify clamps a requested quantity. Also restores the try/catch in addLineItemToCart, which was commented out. The package parses quantity correctly; verified end-to-end against a live 2026-07 store (addLineItemsToCart, updateLineItemsInCart, getCartById) and pinned with a regression test over lines.edges -> node -> quantity. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
The cart tab added
product.productVariants.firstregardless of whether that variant could be bought. Shopify creates a line for an unavailable variant with quantity 0 and reports no userErrors, so on stores whose first variant is out of stock every add showed up as a "0x" line and the +/- buttons looked dead — the server clamped the quantity back to 0.Pick the first variant with availableForSale == true instead, mark out-of-stock products and lines in the UI, and report it when Shopify clamps a requested quantity. Also restores the try/catch in addLineItemToCart, which was commented out.
The package parses quantity correctly; verified end-to-end against a live 2026-07 store (addLineItemsToCart, updateLineItemsInCart, getCartById) and pinned with a regression test over lines.edges -> node -> quantity.