Class: Spree::Variants::OptionTypesFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/spree/variants/option_types_finder.rb

Constant Summary collapse

COLOR_TYPE =
'color'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(variant_ids:) ⇒ OptionTypesFinder

Returns a new instance of OptionTypesFinder.



6
7
8
# File 'app/finders/spree/variants/option_types_finder.rb', line 6

def initialize(variant_ids:)
  @variant_ids = variant_ids
end

Instance Method Details

#executeObject



10
11
12
13
14
# File 'app/finders/spree/variants/option_types_finder.rb', line 10

def execute
  Spree::OptionType.includes(option_values: :variants).where(spree_variants: { id: variant_ids }).
    reorder('spree_option_types.position ASC, spree_option_values.position ASC').
    partition { |option_type| option_type.name.downcase == COLOR_TYPE }.flatten
end