Skip to content

Instantly share code, notes, and snippets.

@redglory
redglory / product_filters.rb
Created June 2, 2015 10:31
Filtering Products by Option Types (Size and Color)
module Spree
module Core
module ProductFilters
# Test for discrete option values selection
def ProductFilters.option_with_values(option_scope, option, values)
# get values IDs for Option with name {@option} and value-names in {@values} for use in SQL below
option_values = Spree::OptionValue.where(:presentation => [values].flatten).joins(:option_type).where(OptionType.table_name => {:name => option}).pluck("#{OptionValue.table_name}.id")
return option_scope if option_values.empty?