Sha256: 62ddabc8cd0da2be8afb3f4bade855cca2ce85104df5a8a0a64066f8e6d286f0
Contents?: true
Size: 1.75 KB
Versions: 3
Compression:
Stored size: 1.75 KB
Contents
Product.class_eval do acts_as_solr :fields => [:name, :description, :is_active, {:price => :float}, :taxon_ids, :price_range, :taxon_names, :brand_property, :color_option, :size_option], :facets=>[:price_range, :taxon_names, :brand_property, :color_option, :size_option] def taxon_ids taxons.map(&:id) end def is_active !deleted_at && (available_on <= Time.zone.now) && (Spree::Config[:allow_backorders] || count_on_hand > 0) end private def taxon_names taxons.map(&:name) end def price_range price_ranges = YAML.load(Spree::Config[:product_price_ranges]) case price when 0..25 price_ranges[0] when 25..50 price_ranges[1] when 50..100 price_ranges[2] when 100..200 price_ranges[3] else price_ranges[4] end end def brand_property pp = ProductProperty.first(:joins => :property, :conditions => {:product_id => self.id, :properties => {:name => 'brand'}}) pp ? pp.value : '' end def color_option get_option_values('color') end def size_option get_option_values('size') end def get_option_values(option_name) sql = <<-eos SELECT DISTINCT ov.id, ov.presentation FROM option_values AS ov LEFT JOIN option_types AS ot ON (ov.option_type_id = ot.id) LEFT JOIN option_values_variants AS ovv ON (ovv.option_value_id = ov.id) LEFT JOIN variants AS v ON (ovv.variant_id = v.id) LEFT JOIN products AS p ON (v.product_id = p.id) WHERE (ot.name = '#{option_name}' AND p.id = #{self.id}); eos OptionValue.find_by_sql(sql).map(&:presentation) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
spree_solr_search-0.40.0 | app/models/product_decorator.rb |
spree_solr_search-0.30.0 | app/models/product_decorator.rb |
spree_solr_search-0.30.0.beta1 | app/models/product_decorator.rb |