Skip to content

Instantly share code, notes, and snippets.

View hachpai's full-sized avatar
👾
chasing ghosts

hachpai hachpai

👾
chasing ghosts
View GitHub Profile
@hachpai
hachpai / product_filters.rb
Last active December 14, 2015 19:39 — forked from Ranger-X/product_filters.rb
In order to make search on range of numerical option values, I've implemented this version. As spree stocks option value in a string, I've to cast it to compare. In the original version of this gist, I was unable to make or join between the created scope. With arel table, no problem.
def ProductFilters.ov_range_test(range1, range2)
ov = Arel::Table.new("spree_option_values")
cast = Arel::Nodes::NamedFunction.new "CAST", [ ov[:presentation].as("integer")]
comparaisons = cast.in(range1..range2)
comparaisons
end
Spree::Product.add_search_scope :screenSize_range_any do |*opts|
conds = opts.map {|o| Spree::ProductFilters.screenSize_filter[:conds][o]}.reject {|c| c.nil?}
scope = conds.shift