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 ⇒ Object
-
#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
A new instance of ProductRatingComponent.
- #render? ⇒ Boolean
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
Returns a new instance of ProductRatingComponent.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/components/www/reviews_io/product_rating_component.rb', line 21 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 ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'app/components/www/reviews_io/product_rating_component.rb', line 46 def call render Www::ReviewsIo::RatingBarComponent.new( value: .to_f, count: total_reviews, link: @link, size_px: @size_px, rounding: @rounding ) end |
#render? ⇒ Boolean
42 43 44 |
# File 'app/components/www/reviews_io/product_rating_component.rb', line 42 def render? resolved_skus.any? && .to_f > @min_rating && total_reviews.positive? end |