Repository navigation
fix(content): show a catalog product at one price everywhere: its best stock, then its lowest price there - #1663
Conversation
…t stock, then its lowest price there Follow-ups from ansvisor#1607 (items 1 and 4). One variant rule. The agent's grid and what the agent is told (shopping-links.js withOffer) take the price of the best stock first, in stock before low stock, then the lowest price there. The path's offer (shopping-path.js offerOf) and a card put in by hand (getProductsForBlock) took the cheapest variant in stock whatever its stock, so a product with an in-stock $199 variant and a low-stock $149 one showed $149 by hand and $199 from the agent. All three now pick with one rule: bestInStock in the new server/src/lib/catalog/offer.js, mirrored in web/src/lib/content/ shopping-path.ts. A sale price alone. A variant with a sale price and no price showed no price at all. priceAmount (the same two files) now takes the sale price when there's no price; a price of 0 is still none, and a sale price above the price still isn't a sale. The server's card text (shopping-blocks.js priceText), the agent's offer line and price spellings, and the editor's priceText all read it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
-
Own change. 9b8fc88 on main (3f6a4d4). It merges cleanly on main, #1653 and #1654. With #1662 there's the one docs conflict the description names (
content-editor.mdx:158). #1664 is stacked on it, and #1664's own commits apply cleanly on main plus this PR's squash. -
One price everywhere. I compared the four places a product's price is picked:
- main's
withOffer(the agent's text and grid): stock rank first, then the lowestpriceAmount, ties to the lower variant id; bestInStockincatalog/offer.js(the path'sofferOf);bestInStockinlib/content/shopping-path.ts(Add › Products, and #1664's check);priceAmountandpriceTexton both sides.
The in-stock rank is the same on both sides:
in_stock,instockandavailablefirst, thenlimited_availability, from the same list (stock.test.jskeepsIN_STOCKandvariantStockalike). Among in-stock variants,withOfferandbestInStockpick the same variant: a variant with no price goes last, and on a tie the stable sort keeps the first, aswithOfferdoes.I ran 200,000 random variant sets through all three pickers and both
priceTexts. They covered every spelling of stock, prices of null, 0, negative and sub-cent, sale prices above, equal to and below the price, and a sale price with no price. There were no differences. - main's
-
Sale price rules, both sides. A price or sale price of 0 is none. A sale price counts only below the price. A sale price with no price (or a price of 0) is now the price. The server's
shopping-blocks.jspositivealso gets theNumber.isFinitecheck now, like the others. -
Tests. On this head the server's catalog, path, links and blocks tests (201) and the web's path, action, dialog and Brief tests (57) pass. Each rule broken on purpose fails a test on both sides: no stock rank, a sale price alone read as none, a sale above the price counted, 0 read as a price, and a variant with no price not put last.
Follow-ups (low):
offerOf's new rule isn't pinned. WithofferOfput back to main's "cheapest,sale_price ?? price" rule (server/src/lib/shopping-path.js:179), every server test still passes. A case inshopping-path.test.jswith an in-stock $199 variant and a low-stock $149 one (expected: $199), plus a sale price above the price, would pin it.- A shared fixture for the two rules. Both files say "change both together". A JSON of variant sets and the variant and price each should pick, read by
offer.test.jsandshopping-path.test.ts(asproduct-block.jsondoes for the card markup), would catch drift. Two small differences such a fixture would settle:readBlockDetails(web/src/lib/actions/shopping-path.ts:228) reads variants without.order('id'), whilewithOfferandgetShoppingCheckorder by id. On an exact tie (same stock, same amount) the card can take a different variant from the grid. That only shows when the two variants have different currencies.- The server's
positivereads a numeric string ("199.00") as a price. The web's reads it as none. PostgREST sendsnumericas a number, so this doesn't happen today.
- The
getProductsForBlockcomment (web/src/lib/actions/shopping-path.ts:271) still says "the price of its cheapest variant in stock". - On the open product question (a refused variant's price): today the Brief's path can show a different price from the card for the same product, when its best in-stock variant is refused. Whichever answer you choose, applying it in
bestInStockitself would keep all four places alike.
Before the API deploy: the web's Add › Products uses the new rule on merge. The Brief's shopping path is built by the API and keeps the prices it was built with, so a path built before the deploy keeps the old rule. Until it's rebuilt, a product with an in-stock $199 variant and a low-stock $149 one can show $149 in the Brief path and $199 on a card put in by hand. Nothing breaks.
Summary
Follow-ups from #1607 (items 1 and 4): a catalog product shows one price everywhere. The rule: its best stock first (in stock before low stock), then the lowest price there.
Before this change:
withOffer) used the best stock first;offerOf) and a card put in by hand (getProductsForBlock) took the cheapest variant in stock, whatever its stock level.So a product with an in-stock $199 variant and a low-stock $149 one showed $149 by hand and $199 from the agent.
All three now use one rule:
bestInStockin the newserver/src/lib/catalog/offer.js, mirrored inweb/src/lib/content/shopping-path.ts.A sale price on its own: a variant with a sale price and no regular price used to show no price at all.
priceAmountnow takes the sale price then.Three tests that pinned the old behaviour were updated on purpose.
Merge note: this PR and #1662 (not in stock) change the same sentence in
docs/guides/content-editor.mdx:158. I'll merge main forward after the first one merges. #1664 is stacked on this one.Where people see it: Add › Products, the shopping path in the Brief, and the agent's product grid. Checked in the browser (local, 1024 px) with a temporary catalog: a product with an in-stock $199 variant and a low-stock $149 variant shows $199.00 in Add › Products. The temporary rows were deleted afterwards.
Open product question (pre-existing): a variant refused in Merchant Center's free listings is left out of the Brief path's price (
offerOf), but counted by the card, the grid, the agent's text and the price check. Should a refused variant's price ever show?Related issue
Follow-ups from #1607's review.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/catalog/offer.test.js src/lib/shopping-path.test.js src/lib/shopping-links.test.js src/lib/shopping-blocks.test.jscd web && npx vitest run src/lib/content/shopping-path.test.tsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Full checks were run once, in one tree with this batch's six follow-up branches merged (#1653, #1654 and the four PRs of this batch):
npm test: 249 files, 3,356 tests passed;vitest(445 files, 4,350 tests) and build: all pass.A pre-push review was done, and its findings for this branch are fixed.
🤖 Generated with Claude Code