Skip to content

example: don't add out-of-stock variants to the cart - #148

Merged
imsujan276 merged 1 commit into
imsujan276:mainfrom
qeepcologne:reland-2026-07
Jul 17, 2026
Merged

example: don't add out-of-stock variants to the cart#148
imsujan276 merged 1 commit into
imsujan276:mainfrom
qeepcologne:reland-2026-07

Conversation

@qeepcologne

Copy link
Copy Markdown
Contributor

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.

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>
@imsujan276
imsujan276 merged commit 9d81a5f into imsujan276:main Jul 17, 2026
2 checks passed
@qeepcologne
qeepcologne deleted the reland-2026-07 branch July 21, 2026 09:20
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