-
-
Save bburdiliak/404ccc0105829f07ae57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomSearch < Spree::Core::Search::Base | |
protected | |
def add_search_scopes(base_scope) | |
statement = nil | |
search.each do |property_name, property_values| | |
property = Spree::Property.find_by_name(property_name.gsub("_any", "")) | |
next unless property | |
substatement = product_property[:property_id].eq(property.id).and(product_property[:value].eq(property_values.first)) | |
property_values[1..-1].each do |pv| | |
substatement = substatement.or product_property[:value].eq(pv) | |
end | |
tail = product[:id].in(Spree::ProductProperty.select(:product_id).where(substatement).map(&:product_id)) | |
statement = statement.nil? ? tail : statement.and(tail) | |
end if search | |
statement ? base_scope.where(statement) : base_scope | |
end | |
def prepare(params) | |
super | |
@properties[:product] = Spree::Product.arel_table | |
@properties[:product_property] = Spree::ProductProperty.arel_table | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment