Class: Spree::Review
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Spree::Review
- Defined in:
- app/models/spree/review.rb
Class Method Summary collapse
Instance Method Summary collapse
- #approve_review ⇒ Object
- #email ⇒ Object
- #feedback_stars ⇒ Object
- #recalculate_product_rating ⇒ Object
- #star_only? ⇒ Boolean
- #verify_purchaser ⇒ Object
Class Method Details
.ransackable_associations ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/spree/review.rb', line 39 def self.ransackable_associations(*) [ "feedback_reviews", "product", "user" ] end |
.ransackable_attributes ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/models/spree/review.rb', line 30 def self.ransackable_attributes(*) [ "approved", "name", "review", "title" ] end |
Instance Method Details
#approve_review ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'app/models/spree/review.rb', line 78 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
57 58 59 |
# File 'app/models/spree/review.rb', line 57 def email user&.email end |
#feedback_stars ⇒ Object
47 48 49 50 51 |
# File 'app/models/spree/review.rb', line 47 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
53 54 55 |
# File 'app/models/spree/review.rb', line 53 def product. if product.present? end |
#star_only? ⇒ Boolean
74 75 76 |
# File 'app/models/spree/review.rb', line 74 def star_only? [title, review].all?(&:blank?) && .present? end |
#verify_purchaser ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/spree/review.rb', line 61 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 |