2014-09-18 27 views
0

當在類似於/服裝的分類羣頁面上時,我如何將其更改爲僅顯示服裝中的產品而非服裝及其子分類?在taxons_controller.rb是它使用spree只顯示當前分類羣中的產品而不是當前分類羣和後代

get_base_scope 

而這又是使用電話

@searcher = build_searcher(params.merge(:taxon => @taxon.id)) 
@products = @searcher.retrieve_products 

在retrieve_products https://github.com/spree/spree/blob/85da083faf81a4b0150e183d2f7aec988e674b07/core/lib/spree/core/search/base.rb#L15

base_scope.in_taxon(taxon) unless taxon.blank? 

https://github.com/spree/spree/blob/b66ea0229646062acb7b6f89ac2447f5ffc862fb/core/app/models/spree/product/scopes.rb#L78甚至說,它包括的範圍後人。我如何覆蓋這個只顯示當前類別的產品?

回答

1

發現我不得不重寫模型中的搜索範圍。以供參考,如果有人發現這一點:

module Spree 
     Product.class_eval do 
     add_search_scope :in_taxon do |taxon| 
      Spree::Product.joins(:taxons).where(Taxon.table_name => { :id => taxon.id }). 
      order("spree_products_taxons.position ASC") 
     end 
     end 
    end