Created
January 21, 2014 19:28
-
-
Save jsqu99/8546583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Spree | |
Product.class_eval do | |
searchable do | |
PRODUCT_OPTION_FACETS.each do |option| | |
string "#{option}_facet", :multiple => true do | |
get_option_values(option.to_s).map(&:presentation) | |
end | |
end | |
PRODUCT_PROPERTY_FACETS.each do |prop| | |
string "#{prop}_facet", :multiple => true do | |
get_product_property(prop.to_s) | |
end | |
end | |
private | |
def get_product_property(prop) | |
#p = Property.find_by_name(prop) | |
#ProductProperty.find(:product_id => self.id, :property_id => p.id) | |
pp = ProductProperty.first(:joins => :property, :conditions => {:product_id => self.id, :spree_properties => {:name => prop.to_s}}) | |
pp.value if pp | |
end | |
def get_option_values(option_name) | |
sql = <<-eos | |
SELECT DISTINCT ov.id, ov.presentation, ov.position | |
FROM spree_option_values AS ov | |
LEFT JOIN spree_ad_hoc_option_values AS ahov ON (ahov.option_value_id = ov.id) | |
LEFT JOIN spree_ad_hoc_option_types AS ahot ON (ahov.ad_hoc_option_type_id = ahot.id) | |
LEFT JOIN spree_option_types AS ot ON (ahot.option_type_id = ot.id) | |
LEFT JOIN spree_products AS p ON (ahot.product_id = p.id) | |
WHERE (ot.name = '#{option_name}' AND p.id = #{self.id}) order by ov.position; | |
eos | |
OptionValue.find_by_sql(sql) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment