diff --git a/app/controllers/spree/products_controller_decorator.rb b/app/controllers/spree/products_controller_decorator.rb index a231a1ce..bf206e37 100644 --- a/app/controllers/spree/products_controller_decorator.rb +++ b/app/controllers/spree/products_controller_decorator.rb @@ -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 } @@ -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) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index c7a7083f..92f4a860 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -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 @@ -16,3 +18,5 @@ def recalculate_rating save end end + +::Spree::Product.prepend(Spree::ProductDecorator) diff --git a/spree_reviews.gemspec b/spree_reviews.gemspec index 9dd61085..19d36756 100644 --- a/spree_reviews.gemspec +++ b/spree_reviews.gemspec @@ -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'