Skip to content

feat(storefront): Show cash discount price in product JSON-LD - #788

Merged
leomp12 merged 2 commits into
mainfrom
feat/product-jsonld-cash-discount
Jul 28, 2026
Merged

feat(storefront): Show cash discount price in product JSON-LD#788
leomp12 merged 2 commits into
mainfrom
feat/product-jsonld-cash-discount

Conversation

@vitorrgg

Copy link
Copy Markdown
Member

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.

vitorrgg and others added 2 commits July 27, 2026 18:26
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 leomp12 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aprovado.

O que foi verificado:

  • Fallback confirmado. getPriceWithDiscount(price, {}) desestrutura type/value de {}!value → retorna o preço intacto (use-prices.ts:28-31). Das 5 lojas no repo, 4 têm discount_option com value: null e 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/storefront passa (5/5 tasks) e o arredondamento aparece no output compilado. ESLint limpo com storefront.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:

  1. O preço do JSON-LD passa a divergir do preço em destaque da PDP — o <strong> grande em Prices.vue renderiza salePrice (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:49?discount= da query, default 0), 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.
  2. O JSON-LD congela o discount_option do settings no SSR, enquanto modules-info.ts:157 pode sobrescrevê-lo em runtime com um valor maior vindo do módulo list_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.

@leomp12
leomp12 merged commit a611eb8 into main Jul 28, 2026
2 checks passed
@leomp12
leomp12 deleted the feat/product-jsonld-cash-discount branch July 28, 2026 08:04
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