【问题标题】:spree only show products in current taxon not current taxon and descendants狂欢只显示当前分类单元中的产品,而不是当前分类单元和后代
【发布时间】:2014-09-18 21:54:45
【问题描述】:

当在 /clothing 之类的分类页面上时,如何将其更改为仅显示服装中的产品而不显示服装及其子类别?在 taxons_controller.rb 它正在调用

@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 它正在使用

get_base_scope

它又在使用:

base_scope.in_taxon(taxon) unless taxon.blank?

https://github.com/spree/spree/blob/b66ea0229646062acb7b6f89ac2447f5ffc862fb/core/app/models/spree/product/scopes.rb#L78 甚至在范围内说它包括后代。如何覆盖它以仅显示当前类别中的产品?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 spree


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      • 2017-09-01
      • 2014-11-11
      • 2019-01-08
      • 1970-01-01
      相关资源
      最近更新 更多