以下のカスタマイズにより、Spree 2.1.0.beta でこれを機能させることができました。
ここの回答に基づいて: Finding records with two specific records in another table
/app/models/spree/product_decorator.rb に新しい製品スコープを追加しました
Spree::Product.class_eval do
add_search_scope :in_all_taxons do |*taxons|
taxons = get_taxons(taxons)
id = arel_table[:id]
joins(:taxons).where(spree_taxons: { id: taxons }).group(id).having(id.count.eq(taxons.size))
end
end
次に、新しいスコープを /app/models/spree/base_decorator.rb に追加して使用しました
Spree::Core::Search::Base.class_eval do
def get_base_scope
base_scope = Spree::Product.active
base_scope = base_scope.in_all_taxons(taxon) unless taxon.blank?
base_scope = get_products_conditions_for(base_scope, keywords)
base_scope = add_search_scopes(base_scope)
base_scope
end
end
これで、標準の検索ヘルパーを使用して製品を取得できるようになりました (つまり、複数の分類群と共にキーワードなどを指定できます)。
# taxon_ids is an array of taxon ids
@searcher = build_searcher(params.merge(:taxon => taxon_ids))
@products = @searcher.retrieve_products
これは私にとってはうまくいき、かなり痛みがなくなりました。しかし、私はより良い選択肢を受け入れています。