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?
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?
taxon_products = current_taxon.products
children_products = current_taxon.children.includes(:products).map(&:products).
flatten.compact.uniq
如果您只需要搜索一个级别的孩子,@PinnyM 的答案很好,但是如果您想找到一个分类单元下的所有产品,您可以使用这样的in_taxon
范围:
children_products = Spree::Product.in_taxon(current_taxon)