Class: Spree::Review
- Inherits:
-
Base
- Object
- Base
- Spree::Review
- Defined in:
- app/models/spree/review.rb
Instance Method Summary collapse
- #approve_review ⇒ Object
- #email ⇒ Object
- #feedback_stars ⇒ Object
- #recalculate_product_rating ⇒ Object
- #star_only? ⇒ Boolean
- #verify_purchaser ⇒ Object
Instance Method Details
#approve_review ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'app/models/spree/review.rb', line 64 def approve_review # Checks if we should auto approve the review. if Spree::Reviews::Config[:approve_star_only] self.approved = true if star_only? elsif Spree::Reviews::Config[:approve_star_only_for_verified_purchaser] self.approved = true if star_only? && verified_purchaser? end end |
#email ⇒ Object
43 44 45 |
# File 'app/models/spree/review.rb', line 43 def email user&.email end |
#feedback_stars ⇒ Object
33 34 35 36 37 |
# File 'app/models/spree/review.rb', line 33 def feedback_stars return 0 if feedback_reviews.size <= 0 ((feedback_reviews.sum(:rating) / feedback_reviews.size) + 0.5).floor end |
#recalculate_product_rating ⇒ Object
39 40 41 |
# File 'app/models/spree/review.rb', line 39 def product. if product.present? end |
#star_only? ⇒ Boolean
60 61 62 |
# File 'app/models/spree/review.rb', line 60 def star_only? [title, review].all?(&:blank?) && .present? end |
#verify_purchaser ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/spree/review.rb', line 47 def verify_purchaser return unless user_id && product_id verified_purchase = Spree::LineItem.joins(:order, :variant) .where.not(spree_orders: { completed_at: nil }) .find_by( spree_variants: { product_id: product_id }, spree_orders: { user_id: user_id } ).present? self.verified_purchaser = verified_purchase end |