Skip to content

Instantly share code, notes, and snippets.

@HeroicEric
Created November 8, 2011 00:23
Show Gist options
  • Select an option

  • Save HeroicEric/1346637 to your computer and use it in GitHub Desktop.

Select an option

Save HeroicEric/1346637 to your computer and use it in GitHub Desktop.
class ProductDecorator < ApplicationDecorator
decorates :product
# Gets all of the OptionValues that is used by a Variant of the Product
#
# Returns an Array of OptionValues
def option_values
option_values = []
model.variants.each do |variant|
option_values << variant.option_values
end
option_values.flatten.uniq
end
# Groups the OptionValues with their OptionType
#
# Returns a Hash with OptionTypes as keys and an Array of OptionValues for values
def grouped_option_values
option_values.group_by(&:option_type)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment