3

I basically want to grab the following in a view:

All the products for the current taxon, and then all the products for the taxon's children. What's the best way to do this? Is there a method already?

4

2 回答 2

8
taxon_products = current_taxon.products
children_products = current_taxon.children.includes(:products).map(&:products).
                                  flatten.compact.uniq
于 2013-06-27T20:15:49.623 回答
2

如果您只需要搜索一个级别的孩子,@PinnyM 的答案很好,但是如果您想找到一个分类单元下的所有产品,您可以使用这样的in_taxon范围

children_products = Spree::Product.in_taxon(current_taxon)
于 2018-02-24T22:22:55.773 回答