fix ld data on offering pages
This commit is contained in:
parent
529fc9148a
commit
1d39e3445e
1 changed files with 52 additions and 61 deletions
|
|
@ -217,6 +217,17 @@ def json_ld_structured_data(context):
|
||||||
offering = context["offering"]
|
offering = context["offering"]
|
||||||
offering_url = request.build_absolute_uri()
|
offering_url = request.build_absolute_uri()
|
||||||
|
|
||||||
|
# Check if we have pricing data available
|
||||||
|
has_pricing_data = False
|
||||||
|
if hasattr(offering, "plans") and offering.plans.exists():
|
||||||
|
# Get all plans with pricing
|
||||||
|
plans_with_prices = offering.plans.filter(
|
||||||
|
plan_prices__isnull=False
|
||||||
|
).distinct()
|
||||||
|
has_pricing_data = plans_with_prices.exists()
|
||||||
|
|
||||||
|
if has_pricing_data:
|
||||||
|
# Use Product type with complete pricing information
|
||||||
data = {
|
data = {
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
"@type": "Product",
|
"@type": "Product",
|
||||||
|
|
@ -233,15 +244,7 @@ def json_ld_structured_data(context):
|
||||||
if hasattr(offering.service, "get_logo") and offering.service.get_logo:
|
if hasattr(offering.service, "get_logo") and offering.service.get_logo:
|
||||||
data["image"] = request.build_absolute_uri(offering.service.get_logo.url)
|
data["image"] = request.build_absolute_uri(offering.service.get_logo.url)
|
||||||
|
|
||||||
# Add offers if available
|
# Create individual offers for each plan with pricing
|
||||||
if hasattr(offering, "plans") and offering.plans.exists():
|
|
||||||
# Get all plans with pricing
|
|
||||||
plans_with_prices = offering.plans.filter(
|
|
||||||
plan_prices__isnull=False
|
|
||||||
).distinct()
|
|
||||||
|
|
||||||
if plans_with_prices.exists():
|
|
||||||
# Create individual offers for each plan
|
|
||||||
offers = []
|
offers = []
|
||||||
all_prices = []
|
all_prices = []
|
||||||
|
|
||||||
|
|
@ -262,42 +265,30 @@ def json_ld_structured_data(context):
|
||||||
}
|
}
|
||||||
offers.append(offer)
|
offers.append(offer)
|
||||||
|
|
||||||
# Add aggregate offer with all individual offers
|
# Add aggregate offer with all required pricing fields
|
||||||
|
if all_prices and offers:
|
||||||
|
# Use the currency from the first plan's first price
|
||||||
|
first_plan_with_prices = plans_with_prices.first()
|
||||||
|
first_currency = first_plan_with_prices.plan_prices.first().currency
|
||||||
|
|
||||||
data["offers"] = {
|
data["offers"] = {
|
||||||
"@type": "AggregateOffer",
|
"@type": "AggregateOffer",
|
||||||
"availability": "https://schema.org/InStock",
|
"availability": "https://schema.org/InStock",
|
||||||
"offerCount": len(offers),
|
"offerCount": len(offers),
|
||||||
"offers": offers,
|
"offers": offers,
|
||||||
|
"lowPrice": str(min(all_prices)),
|
||||||
|
"highPrice": str(max(all_prices)),
|
||||||
|
"priceCurrency": first_currency,
|
||||||
"seller": {"@type": "Organization", "name": "VSHN"},
|
"seller": {"@type": "Organization", "name": "VSHN"},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add lowPrice, highPrice and priceCurrency if we have prices
|
|
||||||
if all_prices:
|
|
||||||
data["offers"]["lowPrice"] = str(min(all_prices))
|
|
||||||
data["offers"]["highPrice"] = str(max(all_prices))
|
|
||||||
# Use the currency from the first plan's first price
|
|
||||||
first_plan_with_prices = plans_with_prices.first()
|
|
||||||
first_currency = first_plan_with_prices.plan_prices.first().currency
|
|
||||||
data["offers"]["priceCurrency"] = first_currency
|
|
||||||
|
|
||||||
# Note: aggregateRating and review fields are not included as this is a B2B
|
# Note: aggregateRating and review fields are not included as this is a B2B
|
||||||
# service marketplace without a review system. These could be added in the future
|
# service marketplace without a review system. These could be added in the future
|
||||||
# if customer reviews/ratings are implemented.
|
# if customer reviews/ratings are implemented.
|
||||||
# Example structure for future implementation:
|
|
||||||
# if hasattr(offering, 'reviews') and offering.reviews.exists():
|
|
||||||
# data["aggregateRating"] = {
|
|
||||||
# "@type": "AggregateRating",
|
|
||||||
# "ratingValue": "4.5",
|
|
||||||
# "reviewCount": "10"
|
|
||||||
# }
|
|
||||||
else:
|
else:
|
||||||
# No pricing available, just basic offer info
|
# No pricing data available - use Organization data instead of Product
|
||||||
data["offers"] = {
|
# to avoid Google Search Console errors for missing required Product fields
|
||||||
"@type": "AggregateOffer",
|
data = organization_data
|
||||||
"availability": "https://schema.org/InStock",
|
|
||||||
"offerCount": offering.plans.count(),
|
|
||||||
"seller": {"@type": "Organization", "name": "VSHN"},
|
|
||||||
}
|
|
||||||
|
|
||||||
elif view_name == "article_list":
|
elif view_name == "article_list":
|
||||||
data = {
|
data = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue