Support priceSpecification in JSON-LD price extraction

Some sites (like Ubiquiti Store) use the priceSpecification nested
format in their JSON-LD structured data instead of direct price
property. Now checks offer.priceSpecification.price as fallback.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-21 21:22:49 -05:00
parent c23cc8353a
commit f188ad4ff1

View file

@ -778,11 +778,17 @@ interface JsonLdProduct {
offers?: JsonLdOffer | JsonLdOffer[];
}
interface JsonLdPriceSpecification {
price?: string | number;
priceCurrency?: string;
}
interface JsonLdOffer {
'@type'?: string;
price?: string | number;
priceCurrency?: string;
lowPrice?: string | number;
priceSpecification?: JsonLdPriceSpecification;
}
function extractJsonLd(
@ -809,12 +815,17 @@ function extractJsonLd(
? product.offers[0]
: product.offers;
// Get price, preferring lowPrice for ranges
const priceValue = offer.lowPrice || offer.price;
// Get price, checking multiple locations:
// 1. lowPrice (for price ranges)
// 2. price (direct)
// 3. priceSpecification.price (nested format used by some sites)
const priceValue = offer.lowPrice || offer.price || offer.priceSpecification?.price;
const currency = offer.priceCurrency || offer.priceSpecification?.priceCurrency || 'USD';
if (priceValue) {
result.price = {
price: parseFloat(String(priceValue)),
currency: offer.priceCurrency || 'USD',
currency,
};
}
}