Skip to content

fix(pdp): respect available_to_sell for backorderable products (BACK-633)#2659

Open
bc-apostoliuk wants to merge 2 commits into
masterfrom
BACK-633
Open

fix(pdp): respect available_to_sell for backorderable products (BACK-633)#2659
bc-apostoliuk wants to merge 2 commits into
masterfrom
BACK-633

Conversation

@bc-apostoliuk
Copy link
Copy Markdown
Contributor

@bc-apostoliuk bc-apostoliuk commented May 14, 2026

What?

Fixes a set of bugs on the PDP where the storefront treated out_of_stock as a hard stop, ignoring whether the variant is still purchasable via backorder (available_to_sell > 0). The Sold Out alert was being shown, the Add to Cart button was being disabled, and the variant message box was rendering "Out of stock" even though the customer could still buy the product via backorder.

Technical details:

  • Template (templates/components/products/add-to-cart.html): The Sold Out alert now renders only when the product is out of stock AND product.available_to_sell is falsy. Rewritten as nested {{#if}} / {{#unless}} block helpers (the prior {{#and product.out_of_stock (unless product.available_to_sell)}} subexpression didn't evaluate as expected in paper-handlebars).
  • Template (templates/components/products/product-view.html): Injected quantityMaxMessage from products.quantity_max so the JS can render the localized over-limit message.
  • assets/js/theme/common/product-details-base.js:
    • updateDefaultAttributesForOOS and updateWalletButtonsView compute canSell = data.instock || data.available_to_sell > 0, falling back to context.availableToSell when the response object lacks a numeric available_to_sell (initial BCData.product_attributes returns null fields).
    • New toggleSoldOutAlert(canSell) hides both the template-rendered Sold Out alert and the variant message box (.productAttributes-message) when the variant can still be sold; shows the alert when it cannot.
    • New updateAddToCartForQty(qty) disables Add to Cart and populates the variant message box with "The maximum purchasable quantity is X" when the requested qty exceeds available_to_sell; re-enables and clears the message when qty drops back within range. Uses a data-qty-limit attribute so it doesn't stomp on other variant messages (e.g. invalid combo warnings).
    • Constructor proactively hides the Sold Out alert on initialization when context.availableToSell > 0, so the template-rendered alert disappears before JS receives variant data.
  • assets/js/theme/common/product-details.js: The initial productAttributes.optionChange call now fires for all products, not just simple ones. This ensures variant-level available_to_sell/instock are fetched on page load for variant products too, so the Sold Out alert/message state is correct before any user interaction.

Requirements

  • CHANGELOG.md entry added (required for code changes only)

Tickets / Documentation

Screenshots (if appropriate)

Screen.Recording.2026-05-14.at.14.47.08.mov

🤖 Generated with Claude Code

…633)

- Hide Sold Out alert and variant message when stock is 0 but backorder is available
- Keep Add to Cart enabled when available_to_sell > 0
- Disable Add to Cart and show "maximum purchasable quantity" message when qty exceeds available_to_sell
- Fetch variant-level data on initial load for all products (not just simple ones) so backorder state is known before any option change
- Use context.availableToSell as fallback when BCData lacks variant-level numeric fields

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@bc-apostoliuk bc-apostoliuk requested a review from a team as a code owner May 14, 2026 11:45
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.

3 participants