only show offer when available
This commit is contained in:
parent
a6d9ee11b0
commit
48affa7000
1 changed files with 21 additions and 13 deletions
|
@ -109,6 +109,11 @@ def json_ld_structured_data(context):
|
||||||
service = context["service"]
|
service = context["service"]
|
||||||
service_url = request.build_absolute_uri()
|
service_url = request.build_absolute_uri()
|
||||||
|
|
||||||
|
# Check if service has offerings with pricing
|
||||||
|
has_offerings = hasattr(service, "offerings") and service.offerings.exists()
|
||||||
|
|
||||||
|
if has_offerings:
|
||||||
|
# Use Product type when we have offerings (which provide the required offers data)
|
||||||
data = {
|
data = {
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
"@type": "Product",
|
"@type": "Product",
|
||||||
|
@ -122,13 +127,16 @@ def json_ld_structured_data(context):
|
||||||
if hasattr(service, "get_logo") and service.get_logo:
|
if hasattr(service, "get_logo") and service.get_logo:
|
||||||
data["image"] = request.build_absolute_uri(service.get_logo.url)
|
data["image"] = request.build_absolute_uri(service.get_logo.url)
|
||||||
|
|
||||||
# Add offerings if available
|
# Add offerings
|
||||||
if hasattr(service, "offerings") and service.offerings.exists():
|
|
||||||
data["offers"] = {
|
data["offers"] = {
|
||||||
"@type": "AggregateOffer",
|
"@type": "AggregateOffer",
|
||||||
"availability": "https://schema.org/InStock",
|
"availability": "https://schema.org/InStock",
|
||||||
"offerCount": service.offerings.count(),
|
"offerCount": service.offerings.count(),
|
||||||
}
|
}
|
||||||
|
else:
|
||||||
|
# Use Organization data when no offerings are available
|
||||||
|
# This avoids Google Search Console errors for Product without required fields
|
||||||
|
data = organization_data
|
||||||
|
|
||||||
elif view_name == "provider_detail" and "provider" in context:
|
elif view_name == "provider_detail" and "provider" in context:
|
||||||
provider = context["provider"]
|
provider = context["provider"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue