Class: Spree::ProductReview

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/product_review.rb

Instance Method Summary collapse

Instance Method Details

#approve!Object



25
26
27
# File 'app/models/spree/product_review.rb', line 25

def approve!
  update(approved: true)
end

#pending?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/models/spree/product_review.rb', line 21

def pending?
  !approved?
end

#reject!Object



29
30
31
# File 'app/models/spree/product_review.rb', line 29

def reject!
  update(approved: false)
end

#review_dateObject



69
70
71
# File 'app/models/spree/product_review.rb', line 69

def review_date
  created_at.strftime("%B %d, %Y at %I:%M%p")
end

#reviewer_nameObject



61
62
63
64
65
66
67
# File 'app/models/spree/product_review.rb', line 61

def reviewer_name
  if user&.name && show_identifier
    user.name
  else
    "Anonymous"
  end
end

#validate_image_sizeObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/spree/product_review.rb', line 44

def validate_image_size
  return unless images.attached?

  section = Spree::PageSections::AddAReview.first
  max_mb = section&.preferred_max_image_size_mb || 5
  max_bytes = max_mb.megabytes

  images.each do |image|
    if image.blob.byte_size > max_bytes
      errors.add(
        :images,
        "Each image must be smaller than #{max_mb}MB"
      )
    end
  end
end

#validate_max_imagesObject



33
34
35
36
37
38
39
40
41
42
# File 'app/models/spree/product_review.rb', line 33

def validate_max_images
  return unless images.attached?

  section = Spree::PageSections::AddAReview.first
  max = section&.preferred_max_images_upload || 5

  if images.count > max
    errors.add(:images, "Maximum #{max} images allowed")
  end
end