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[]; offers?: JsonLdOffer | JsonLdOffer[];
} }
interface JsonLdPriceSpecification {
price?: string | number;
priceCurrency?: string;
}
interface JsonLdOffer { interface JsonLdOffer {
'@type'?: string; '@type'?: string;
price?: string | number; price?: string | number;
priceCurrency?: string; priceCurrency?: string;
lowPrice?: string | number; lowPrice?: string | number;
priceSpecification?: JsonLdPriceSpecification;
} }
function extractJsonLd( function extractJsonLd(
@ -809,12 +815,17 @@ function extractJsonLd(
? product.offers[0] ? product.offers[0]
: product.offers; : product.offers;
// Get price, preferring lowPrice for ranges // Get price, checking multiple locations:
const priceValue = offer.lowPrice || offer.price; // 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) { if (priceValue) {
result.price = { result.price = {
price: parseFloat(String(priceValue)), price: parseFloat(String(priceValue)),
currency: offer.priceCurrency || 'USD', currency,
}; };
} }
} }