mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-04-25 00:36:32 +02:00
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:
parent
c23cc8353a
commit
f188ad4ff1
1 changed files with 14 additions and 3 deletions
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue