Permalink
Browse files

Bugfix: not filter by children taxon if ancestors is not selected

  • Loading branch information...
ademidov committed Mar 20, 2012
1 parent af0cc8b commit 0e6e895543ae5b9c714fab0c5119c2d10d1660db
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/spree/search/thinking_sphinx.rb
@@ -22,8 +22,9 @@ def get_products_conditions_for(base_scope,query)
# filters = {'183' => [174], '2' => [144, 145]}
if filters.present?
+ selected_taxon_ids = filters.values.flatten.map &:to_i
filters.each do |filter_taxon_id, taxon_ids|
- if taxon_ids.any?(&:present?) && Spree::Taxon.find_by_id(filter_taxon_id)
+ if taxon_ids.any?(&:present?) && filter_taxon_available?(filter_taxon_id, selected_taxon_ids)
with_opts.merge!("#{filter_taxon_id}_taxon_ids" => taxon_ids)
end
end
@@ -106,6 +107,14 @@ def get_base_scope
base_scope
end
+ def filter_taxon_available?(filter_taxon_id, selected_taxon_ids)
+ filter_taxon = Spree::Taxon.find_by_id(filter_taxon_id) || return
+ return true if filter_taxon.root?
+
+ nearest_filter_ancestor = filter_taxon.ancestors.filters.last
+ nearest_filter_ancestor.id.in?(selected_taxon_ids) || nearest_filter_ancestor == taxon
+ end
+
# corrects facets for taxons
def correct_facets(facets, query, search_options)
return facets unless filters.present?

0 comments on commit 0e6e895

Please sign in to comment.