Ruby on rails 在SpreeCommerce API中使用分类单元id搜索产品

Ruby on rails 在SpreeCommerce API中使用分类单元id搜索产品,ruby-on-rails,api,spree,Ruby On Rails,Api,Spree,我正在尝试使用taxon\u id作为过滤器从SpreeCommerce API搜索产品。使用洗劫宝石进行搜索。我试过: /api/products?q[taxon_ids_cont]=x (其中x是分类单元的id)。我也尝试过: /api/products?q[taxon_ids_in]=x 并且都返回所有产品的json,而不进行过滤。我应该在products端点上使用哪些参数来获取通过taxon\u id过滤的产品,或者我该如何解决这个问题?我找到了一个解决方案。SpreeCommerc

我正在尝试使用
taxon\u id
作为过滤器从SpreeCommerce API搜索产品。使用洗劫宝石进行搜索。我试过:

/api/products?q[taxon_ids_cont]=x
(其中x是分类单元的id)。我也尝试过:

/api/products?q[taxon_ids_in]=x

并且都返回所有产品的json,而不进行过滤。我应该在
products
端点上使用哪些参数来获取通过
taxon\u id
过滤的产品,或者我该如何解决这个问题?

我找到了一个解决方案。SpreeCommerce API在taxons controller中有一个名为
products
的操作,可以通过
/API/taxons/products
端点访问该操作

def products
    # Returns the products sorted by their position with the classification
    # Products#index does not do the sorting.
    taxon = Spree::Taxon.find(params[:id])
    @products = taxon.products.ransack(params[:q]).result
    @products = @products.page(params[:page]).per(500 || params[:per_page])
    render "spree/api/products/index"
  end
端点接受一个参数
id
,并可选地接受一个
:q
参数,该参数为

例如,url:

/api/taxons/products?id=1
将返回分类单元下所有产品的json,id为1

/api/taxons/products?id=1&q[name_cont]=Bag
将返回分类单元下id为1的产品json,其名称包含单词Bag。我不知道为什么官方API指南中缺少这条信息