我试图使用SpreeCommerce作为过滤器从taxon_ids
API中搜索产品。搜索api使用ransack宝石谓词进行搜索。我试过:
/api/products?q[taxon_ids_cont]=x
(其中x是一个分类单元的id )。我也尝试过:
/api/products?q[taxon_ids_in]=x
并且都不需要过滤就可以返回所有产品的json。我应该在products
端点上使用哪些参数来获取由taxon_ids
过滤的产品,或者如何解决这个问题?
发布于 2014-06-29 13:46:25
我找到了解决办法。SpreeCommerce API在分类法控制器中有一个名为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
参数,即ransack创业板谓词
例如,url:
/api/taxons/products?id=1
将返回id
为1的分类法下所有产品的json。
/api/taxons/products?id=1&q[name_cont]=Bag
将返回分类单元下的产品json,其id为1,它们的名称中包含单词袋。我不知道为什么官方API指南缺少这条信息。
https://stackoverflow.com/questions/24437265
复制相似问题