Repository navigation
feat(content): name the product cards whose price changed in the catalog in Before you publish - #1664
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]>
…log in Before you publish Follow-up from ansvisor#1610 (item 4). A product card's price is written when it goes in, by hand or in the agent's grid, and stays. Before you publish checked the stock and refusals of the products a page links, not the prices its cards show. - getShoppingCheck reads each product's price now, as a card would show it: its best stock's variant (bestInStock), priceText. - readPage collects the product cards in the page's HTML blocks, each with the price it shows (the editor's own card markup, product-block.ts). - shoppingLinks compares them: a card of a product that sells whose price isn't the catalog's now, each product once (`prices`). A card without a price, a product that no longer sells (listed to remove already) or one whose price wasn't read is left alone. - Before you publish shows a row of its own beside Shopping links: "2 product cards show an old price", each with the page's price and the price now ("no price" when the catalog has none), and to put the product in again to show today's. priceText moves to lib/content/shopping-path.ts so the server action can use it; _shopping-path.tsx re-exports it. Stacked on fix/shopping-one-price-rule: the price now is that branch's rule. Only the products the shopping path checks are compared: a card put in by hand of a product outside the path isn't read here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ugh Add › Products Before you publish's old-price line said to put the product in again through "Insert › Products", but the menu is Add › Products, and it didn't say to delete the old card: the check lists every card whose price doesn't match, so a card left in place keeps the warning. It now reads "To show today's, replace the card: delete it and add the product again (Add › Products)." The editor guide says the same. 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. 4a45572 and 6c8ad72 on top of #1663 (9b8fc88). They apply cleanly on main plus #1663's squash. Merged with the branch instead, they conflict in three files, because #1663's changes would come in twice. So this PR goes in after #1663 is squashed and
mainis merged into it. With #1662 it has the same one-sentence docs conflict as #1663. - The price now is
bestInStockover every in-stock variant, refused ones included, ordered by id. That's how the card (getProductsForBlock) and the agent's grid (withOffer) pick it, so a card put in today isn't flagged. It's read only for a product in the path whose state isok. - The cards.
readPagereadsa.ansvisor-productinside HTML blocks only. Its firstspanis the price in both the editor's and the API's markup, and the test builds the card with the editor's ownproductBlockHtml. A card is matched to its product by the samehrefKeyas the links. Cards without a price, products that no longer sell, products whose price wasn't read, and products outside the path are left alone. Each product is listed once. - The row is a
check, so it informs and doesn't block. It's shown only when a card is listed. "no price now" covers a product that lost its price. - Speed. One pass over the blocks and the cards. No new regex.
- Tests. On this head the shopping-check, rules, action and Before you publish tests pass, and so do the editor's folder and
lib/content(1,396 tests; threepage.test.tsxtests timed out under the full run's load and pass alone). Breaking each piece on purpose fails a test: ignoring the cards, comparing a product that no longer sells or one that wasn't read, listing a product twice, reading no cards, and dropping the row.
Follow-ups (low):
-
Tests that don't fail yet:
- The editor not passing
page.cardstoshoppingLinks(_draft-editor.tsx):page.test.tsxstill passes, because the Before you publish test is givenpricesdirectly. - A card with no price, for a product that has one now, being compared.
readPagetaking any link inside an HTML block as a card.
One case each would pin them.
- The editor not passing
-
"Changed in your catalog" isn't always true. A card put in by hand since #1607, under the old "cheapest in stock" rule, shows as an old price until it's replaced, even if the catalog never changed. That's what the description means by "once". The row's fix (replace the card) is still right. Only the guide's sentence "whose price has changed in your catalog since they went in" overstates it. The guide could also say that only the shopping path's products are checked.
-
Compared as text. The card's price was formatted in the browser (by hand) or on the API (the grid), and today's price is formatted in the server action. That's the same for USD, EUR and GBP, but a runtime's ICU data could differ for a rarer currency. Comparing the amount and the currency instead of the text would rule that out.
Before the API deploy: web only. The check runs in a server action on catalog_variants columns that are already on prod, so it works on merge. Cards on prod today come only from Add › Products, since the agent's grid needs the API.
Summary
Follow-up from #1610 (item 4): Before you publish names the product cards whose price changed in the catalog.
Stacked on #1663 (one price rule), which sets the price a card should show now. This PR's own commits: 4a45572 and 6c8ad72.
A product card's price is written when it goes in, by hand or in the agent's grid, and stays. Before you publish checked the stock and refusals of the products a page links, but not the prices its cards show.
getShoppingCheckreads each product's current price, as a card would show it (bestInStock,priceText).readPagecollects the product cards in the page's HTML blocks, each with the price it shows (the editor's own card markup).shoppingLinkscompares them and returnsprices: each card of a product that still sells whose price isn't the catalog's now, one per product.priceTextmoves tolib/content/shopping-path.tsso the server action can use it;_shopping-path.tsxre-exports it.Limits (follow-ups):
Where people see it: Content Editor › Mark ready, Export or Send → Before you publish. Covered by
_before-publish.test.tsx. It wasn't clicked in the browser, because it needs a built shopping path, which the local demo brand doesn't have.Related issue
Follow-up from #1610'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 web && npx vitest run "src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx" src/lib/content/shopping-check.test.ts src/lib/actions/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