Skip to content

Instantly share code, notes, and snippets.

@BenMorganIO
Last active August 29, 2015 14:05
Show Gist options
  • Save BenMorganIO/5577d5d4686d61ebd6f4 to your computer and use it in GitHub Desktop.
Save BenMorganIO/5577d5d4686d61ebd6f4 to your computer and use it in GitHub Desktop.
similar products through taxes
Spree::Order.class_eval do
def similiar_products(limit)
# products -> tax_category -> tax_rates -> adjustments -> orders -> products
tax_rates = self.products.map do |product|
product.tax_category.tax_rates
end.flatten
adjustments = tax_rates.map(&:adjustments).flatten
orders = adjustments.map(&:order).compact
orders.map(&:products).flatten.first(limit)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment