4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/helpers/workarea/storefront/reviews_schema_org_helper.rb', line 4
def product_schema(product, related_products: nil)
schema = super.merge(
'review': product.reviews.map do |review|
{
'@type': 'Review',
'author': review.user_info,
'datePublished': review.created_at.strftime('%Y-%m-%d'),
'description': review.body,
'name': review.title,
'reviewRating': {
'@type': 'Rating',
'bestRating': '5',
'worstRating': '1',
'ratingValue': review.rating.round(2).to_s
}
}
end
)
if product.total_reviews > 0 && product.average_rating.present?
schema['aggregateRating'] = {
'reviewCount': product.total_reviews.to_s,
'ratingValue': product.average_rating.round(2).to_s
}
end
schema
end
|