Sha256: fd991a3fe71b35de233fa1abe39152a5edf097d91d54cc2b34745fced82c39ff
Contents?: true
Size: 846 Bytes
Versions: 5
Compression:
Stored size: 846 Bytes
Contents
Product.class_eval do include ActionView::Helpers::NumberHelper def option_values option_types.map{|i| i.option_values }.flatten.uniq end def grouped_option_values option_values.group_by(&:option_type) end def variant_options_hash return @variant_options_hash if @variant_options_hash @variant_options_hash = Hash[grouped_option_values.map{ |type, values| [type.id.inspect, Hash[values.map{ |value| [value.id.inspect, Hash[variants.includes(:option_values).select{ |variant| variant.option_values.select{ |val| val.id == value.id && val.option_type_id == type.id }.length == 1 }.map{ |v| [ v.id, { :id => v.id, :count => v.count_on_hand, :price => number_to_currency(v.price) } ] }] ] }]] }] @variant_options_hash end end
Version data entries
5 entries across 5 versions & 1 rubygems