From ccf6ddad408f4a5bf82cd7508832874b947a8d77 Mon Sep 17 00:00:00 2001 From: nlevesque Date: Wed, 29 Jul 2026 00:40:41 +0200 Subject: [PATCH] Fix variant pricing: resolve reverse prices from *-holo fields, hide unpriced rows TCGdex publishes reverse-holo prices in avg-holo when a card has no holo variant (e.g. swsh2-83: reverse=true, holo=false, avg-reverse absent). Variant rows are now shown only when a real price exists, and collection pricing resolves Reverse via avg-reverse ?? avg-holo ?? avg. --- src/lib/collection.ts | 10 +++++++++- src/pages/card/[id].astro | 26 ++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/lib/collection.ts b/src/lib/collection.ts index caa6bbf..1c2acae 100644 --- a/src/lib/collection.ts +++ b/src/lib/collection.ts @@ -35,7 +35,15 @@ export async function priceCollectionCards( const cardmarket = detail?.pricing?.cardmarket; if (cardmarket) { const priceKey = variantPriceMap[card.variant ?? ""] ?? "avg"; - price = cardmarket[priceKey] ?? cardmarket.avg ?? 0; + // TCGdex quirk: reverse prices may live in the *-holo + // fields when the card has no holo variant + price = + cardmarket[priceKey] ?? + (card.variant === "Reverse" + ? cardmarket["avg-holo"] + : undefined) ?? + cardmarket.avg ?? + 0; } return { ...card, price, totalPrice: price }; }), diff --git a/src/pages/card/[id].astro b/src/pages/card/[id].astro index df3f91a..2dcf6f7 100644 --- a/src/pages/card/[id].astro +++ b/src/pages/card/[id].astro @@ -53,15 +53,29 @@ const availableVariants = card.variants const variantPrices: { label: string; price: number }[] = []; -// Always include the base avg price (0 when no Cardmarket data) -variantPrices.push({ label: "Base", price: cardmarket?.avg ?? 0 }); +// TCGdex quirk: when a card has a reverse variant but no holo variant, +// the reverse price is published in the *-holo fields (avg-reverse absent) +const priceKeyFor = (variant: string): string => { + if (variant === "reverse" && card.variants?.holo === false) { + return cardmarket?.["avg-reverse"] != null + ? "avg-reverse" + : "avg-holo"; + } + return variantPriceMap[variant]; +}; -// Add prices for each available variant +// Base price row, only when actually priced +if (cardmarket?.avg != null) { + variantPrices.push({ label: "Base", price: cardmarket.avg }); +} + +// Variant rows, only when the price actually exists for (const variant of availableVariants) { if (variant === "normal") continue; // normal uses the base avg, already added - const priceKey = variantPriceMap[variant]; - const price = cardmarket?.[priceKey] ?? 0; - variantPrices.push({ label: variantLabels[variant] ?? variant, price }); + const price = cardmarket?.[priceKeyFor(variant)]; + if (price != null) { + variantPrices.push({ label: variantLabels[variant] ?? variant, price }); + } } // Determine which tabs have content