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
The answer by @PinnyM is fine if you only need to search one level of children, but if you want to find all the products under a taxon, you can use the in_taxon scope like this:
children_products = Spree::Product.in_taxon(current_taxon)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With