Class: Www::ReviewsIo::ProductRatingComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Www::ReviewsIo::ProductRatingComponent
- Includes:
- Concerns::ReviewsIoSupport
- Defined in:
- app/components/www/reviews_io/product_rating_component.rb
Overview
Displays product rating from Reviews.io data stored in the database.
This replaces the old API-based rating lookup with a database query.
Usage:
<%= render Www::ReviewsIo::ProductRatingComponent.new(skus: ['SKU-001']) %>
<%= render Www::ReviewsIo::ProductRatingComponent.new(skus: ['SKU-001'], link: '#reviews') %>
<%= render Www::ReviewsIo::ProductRatingComponent.new(skus: ['SKU-001', 'SKU-002']) %>
<%= render Www::ReviewsIo::ProductRatingComponent.new(product_line: 'towel-warmer-classic-infinity') %>
Expansion options:
- include_variants: true - expand each SKU to include all item variants (default: true)
- include_pl_siblings: true - expand to include all items in same product line (default: false)
Instance Method Summary collapse
-
#call ⇒ String
Renders the rating bar with the aggregated Reviews.io data.
-
#initialize(skus: nil, product_line: nil, include_variants: true, include_pl_siblings: false, link: nil, size_px: 12, rounding: :floor, min_rating: 3) ⇒ ProductRatingComponent
constructor
Builds a rating display from Reviews.io data for the given SKUs or product line.
-
#render? ⇒ Boolean
Whether the component should render.
Methods inherited from ApplicationComponent
#cms_link, #fetch_or_fallback, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags
Constructor Details
#initialize(skus: nil, product_line: nil, include_variants: true, include_pl_siblings: false, link: nil, size_px: 12, rounding: :floor, min_rating: 3) ⇒ ProductRatingComponent
Builds a rating display from Reviews.io data for the given SKUs or product line.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/components/www/reviews_io/product_rating_component.rb', line 32 def initialize( skus: nil, product_line: nil, include_variants: true, include_pl_siblings: false, link: nil, size_px: 12, rounding: :floor, min_rating: 3 ) super() @skus = Array(skus).flatten.compact_blank if skus.present? @product_line = product_line @include_variants = include_variants @include_pl_siblings = include_pl_siblings @link = link @size_px = size_px @rounding = rounding @min_rating = end |
Instance Method Details
#call ⇒ String
Renders the rating bar with the aggregated Reviews.io data.
64 65 66 67 68 69 70 71 72 |
# File 'app/components/www/reviews_io/product_rating_component.rb', line 64 def call render Www::ReviewsIo::RatingBarComponent.new( value: .to_f, count: total_reviews, link: @link, size_px: @size_px, rounding: @rounding ) end |
#render? ⇒ Boolean
Whether the component should render.
56 57 58 |
# File 'app/components/www/reviews_io/product_rating_component.rb', line 56 def render? resolved_skus.any? && .to_f > @min_rating && total_reviews.positive? end |