feat(storefront): Show cash discount price in product JSON-LD - #788
Conversation
Product JSON-LD offers now apply the store's configured payment discount (settings.modules.list_payments.discount_option), reusing getPriceWithDiscount from use-prices. Falls back to the regular price when no discount is configured, so behavior is unchanged for stores that don't set it.
Applying a percentage discount to the price produces floating point noise and 3+ decimal places, which were serialized raw into the product JSON-LD (e.g. 89.90 -12% emitted 79.11200000000001, and 129.90 -5% emitted 123.405). Rounds to 2 decimals at the JSON-LD call site, matching the existing catalog feed behaviour in packages/feeds (render-catalog.ts uses toFixed(2) on the same calculation). Kept local to BaseHead so the shared getPriceWithDiscount used by cart/checkout is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y7qSxBB2tGRCvHa6h8tNRS
leomp12
left a comment
There was a problem hiding this comment.
Aprovado.
O que foi verificado:
- Fallback confirmado.
getPriceWithDiscount(price, {})desestruturatype/valuede{}→!value→ retorna o preço intacto (use-prices.ts:28-31). Das 5 lojas no repo, 4 têmdiscount_optioncomvalue: nulle não mudam em nada. Só a efacini (Pix, 12%, subtotal) é afetada. - Sem risco de runtime. Mudança é SSR/render-time, restrita ao
<script type="application/ld+json">do head da PDP. Não toca checkout, cart nem estado de cliente. - Sem risco de crash.
settings.modules?.list_payments?.discount_option || {}é optional chaining com fallback. - Build do
@cloudcommerce/storefrontpassa (5/5 tasks) e o arredondamento aparece no output compilado. ESLint limpo comstorefront.staged.eslintrc.cjs.
Fix aplicado em 335d6ed — preço com ruído de float e 3+ casas decimais ia cru pro JSON-LD:
| Preço | Desconto | Antes | Depois |
|---|---|---|---|
| 89,90 | 12% | 79.11200000000001 |
79.11 |
| 129,90 | 5% | 123.405 |
123.41 |
| 1999,90 | 15% | 1699.915 |
1699.92 |
Arredondado no call site do JSON-LD com Math.round(x * 100) / 100, seguindo o precedente do feed de catálogo (packages/feeds/src/firebase/render-catalog.ts:152,154 usa toFixed(2) na mesma conta). Mantido local ao BaseHead para não mexer no getPriceWithDiscount compartilhado, que é usado por cart/checkout. Arredonda para cima, que é o lado seguro — nunca anuncia menos do que se cobra.
Ressalvas registradas, decididas conscientemente:
- O preço do JSON-LD passa a divergir do preço em destaque da PDP — o
<strong>grande emPrices.vuerenderizasalePrice(preço cheio), e o desconto à vista fica numa linha secundária. É o gatilho de "Mismatched value (page crawl): price" no Merchant Center. Também vale notar que o feed do repo usa uma fonte independente para desconto (render-catalog.ts:49lê?discount=da query, default0), então feed e JSON-LD só coincidem se alguém alinhar os dois à mão. Confirmado com o time que é o comportamento pretendido — é o objetivo do PR. - O JSON-LD congela o
discount_optiondo settings no SSR, enquantomodules-info.ts:157pode sobrescrevê-lo em runtime com um valor maior vindo do módulolist_payments. A linha visível pode subir depois da hidratação e o JSON-LD ficar defasado. Não bloqueia, mas fica registrado.
Não houve QA visual. Vale conferir o ld+json no view-source de uma PDP da efacini depois do deploy e passar no Rich Results Test — é barato e é o único jeito de validar o resultado renderizado.
Product JSON-LD offers now apply the store's configured payment discount (settings.modules.list_payments.discount_option), reusing getPriceWithDiscount from use-prices. Falls back to the regular price when no discount is configured, so behavior is unchanged for stores that don't set it.