Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spree v4.0 #174

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/controllers/spree/products_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Spree::ProductsController.class_eval do
helper Spree::ReviewsHelper
module Spree::ProductsControllerDecorator
def self.prepended(base)
base.helper Spree::ReviewsHelper
end

reviews_fields = [:avg_rating, :reviews_count]
reviews_fields.each { |attrib| Spree::PermittedAttributes.product_attributes << attrib }
Expand All @@ -8,3 +10,5 @@
reviews_fields.each { |attrib| class_variable_set(:@@product_attributes, class_variable_get(:@@product_attributes).push(attrib)) }
end
end

::Spree::ProductsController.prepend(Spree::ProductsControllerDecorator)
8 changes: 6 additions & 2 deletions app/models/spree/product_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Add access to reviews/ratings to the product model
Spree::Product.class_eval do
has_many :reviews
module Spree::ProductDecorator
def self.prepended(base)
base.has_many :reviews
end

def stars
avg_rating.try(:round) || 0
Expand All @@ -16,3 +18,5 @@ def recalculate_rating
save
end
end

::Spree::Product.prepend(Spree::ProductDecorator)
2 changes: 1 addition & 1 deletion spree_reviews.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

spree_version = '>= 3.1.0', '< 4.0'
spree_version = '>= 3.1.0', '< 5.0'
s.add_runtime_dependency 'spree_core', spree_version
s.add_runtime_dependency 'spree_auth_devise', spree_version
s.add_runtime_dependency 'spree_extension'
Expand Down