Skip to content

fix(content): show a catalog product at one price everywhere: its best stock, then its lowest price there - #1663

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/shopping-one-price-rule
Oct 28, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/shopping-one-price-rule

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

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:

    • the agent's grid and what the agent is told (withOffer) used the best stock first;
    • the path's offer (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: bestInStock in the new server/src/lib/catalog/offer.js, mirrored in web/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. priceAmount now takes the sale price then.

    • A price of 0 still means no price.
    • A sale price above the regular price still isn't a sale.
  • 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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. 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.js
  2. cd web && npx vitest run src/lib/content/shopping-path.test.ts
  3. With a product that has an in-stock $199 variant and a low-stock $149 one: Add › Products, the Brief path and the agent's grid all say $199.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

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):

  • server format, lint and npm test: 249 files, 3,356 tests passed;
  • web format, lint (0 errors), typecheck, 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

…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]>
@mintlify

mintlify Bot commented Oct 28, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 9b8fc88.

Approve preview

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 lowest priceAmount, ties to the lower variant id;
    • bestInStock in catalog/offer.js (the path's offerOf);
    • bestInStock in lib/content/shopping-path.ts (Add › Products, and #1664's check);
    • priceAmount and priceText on both sides.

    The in-stock rank is the same on both sides: in_stock, instock and available first, then limited_availability, from the same list (stock.test.js keeps IN_STOCK and variantStock alike). Among in-stock variants, withOffer and bestInStock pick the same variant: a variant with no price goes last, and on a tie the stable sort keeps the first, as withOffer does.

    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.

  • 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.js positive also gets the Number.isFinite check 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):

  1. offerOf's new rule isn't pinned. With offerOf put back to main's "cheapest, sale_price ?? price" rule (server/src/lib/shopping-path.js:179), every server test still passes. A case in shopping-path.test.js with an in-stock $199 variant and a low-stock $149 one (expected: $199), plus a sale price above the price, would pin it.
  2. 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.js and shopping-path.test.ts (as product-block.json does 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'), while withOffer and getShoppingCheck order 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 positive reads a numeric string ("199.00") as a price. The web's reads it as none. PostgREST sends numeric as a number, so this doesn't happen today.
  3. The getProductsForBlock comment (web/src/lib/actions/shopping-path.ts:271) still says "the price of its cheapest variant in stock".
  4. 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 bestInStock itself 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.

@gkhngyk
gkhngyk merged commit 3904cce into ansvisor:main Oct 28, 2026
7 checks passed
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