Skip to content

Commit

Permalink
Merge pull request #2464 from jhawthorn/deprecate_searcher_method_mis…
Browse files Browse the repository at this point in the history
…sing

Deprecate Searcher::Base method_missing properties magic
  • Loading branch information
jhawthorn authored Jan 25, 2018
2 parents 7ad9274 + 9eef6be commit afdb7f9
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions core/lib/spree/core/search/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ def current_currency

def retrieve_products
@products = get_base_scope
curr_page = page || 1
curr_page = @properties[:page] || 1

unless Spree::Config.show_products_without_price
@products = @products.joins(:prices).merge(Spree::Price.where(pricing_options.search_arguments)).distinct
end
@products = @products.page(curr_page).per(per_page)
@products = @products.page(curr_page).per(@properties[:per_page])
end

def method_missing(name)
if @properties.key? name
if @properties.key?(name)
Spree::Deprecation.warn "Accessing Searcher's #{name} property using #{self.class.name}##{name} is deprecated without replacement"
@properties[name]
else
super
Expand All @@ -47,8 +48,8 @@ def method_missing(name)

def get_base_scope
base_scope = Spree::Product.display_includes.available
base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
base_scope = get_products_conditions_for(base_scope, keywords)
base_scope = base_scope.in_taxon(@properties[:taxon]) unless @properties[:taxon].blank?
base_scope = get_products_conditions_for(base_scope, @properties[:keywords])
base_scope = add_search_scopes(base_scope)
base_scope = add_eagerload_scopes(base_scope)
base_scope
Expand All @@ -71,19 +72,21 @@ def add_eagerload_scopes(scope)
# `where` constraints affecting joined tables are added to the search;
# which is the case as soon as a taxon is added to the base scope.
scope = scope.preload(master: :currently_valid_prices)
scope = scope.preload(master: :images) if include_images
scope = scope.preload(master: :images) if @properties[:include_images]
scope
end

def add_search_scopes(base_scope)
search.each do |name, scope_attribute|
scope_name = name.to_sym
if base_scope.respond_to?(:search_scopes) && base_scope.search_scopes.include?(scope_name.to_sym)
base_scope = base_scope.send(scope_name, *scope_attribute)
else
base_scope = base_scope.merge(Spree::Product.ransack({ scope_name => scope_attribute }).result)
if @properties[:search]
@properties[:search].each do |name, scope_attribute|
scope_name = name.to_sym
if base_scope.respond_to?(:search_scopes) && base_scope.search_scopes.include?(scope_name.to_sym)
base_scope = base_scope.send(scope_name, *scope_attribute)
else
base_scope = base_scope.merge(Spree::Product.ransack({ scope_name => scope_attribute }).result)
end
end
end if search
end
base_scope
end

Expand Down

0 comments on commit afdb7f9

Please sign in to comment.