Class: ProductTemplates::SwatchesViewModel

Inherits:
ProductViewModel
  • Object
show all
Includes:
OptionSetViewModel
Defined in:
app/view_models/workarea/storefront/product_templates/swatches_view_model.rb

Instance Method Summary collapse

Instance Method Details



19
20
21
22
# File 'app/view_models/workarea/storefront/product_templates/swatches_view_model.rb', line 19

def browse_link_options
  return super unless current_browse_selection.present?
  super.merge(browse_swatch_option.slug => current_browse_selection)
end

#browse_swatch_optionObject



24
25
26
27
# File 'app/view_models/workarea/storefront/product_templates/swatches_view_model.rb', line 24

def browse_swatch_option
  @browse_swatch_option ||=
    Workarea.config.browse_swatch_option.call(self, options_for_selection)
end

#current_browse_selectionObject



34
35
36
37
# File 'app/view_models/workarea/storefront/product_templates/swatches_view_model.rb', line 34

def current_browse_selection
  return if browse_swatch_option.blank?
  options[browse_swatch_option.slug]
end

#current_browse_selection?(selection) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/view_models/workarea/storefront/product_templates/swatches_view_model.rb', line 39

def current_browse_selection?(selection)
  current_browse_selection == selection
end

#display_browse_swatches?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'app/view_models/workarea/storefront/product_templates/swatches_view_model.rb', line 29

def display_browse_swatches?
  return false if model.try(:browse_option).present?
  browse_swatch_option.present?
end

#images_by_optionObject



6
7
8
9
10
11
12
13
# File 'app/view_models/workarea/storefront/product_templates/swatches_view_model.rb', line 6

def images_by_option
  @images_by_option ||= model
    .images
    .reject { |i| i.option.blank? }
    .group_by { |i| i.option.optionize }
    .with_indifferent_access
    .transform_keys(&:optionize)
end

#swatches_by_optionObject



15
16
17
# File 'app/view_models/workarea/storefront/product_templates/swatches_view_model.rb', line 15

def swatches_by_option
  @swatches_by_option ||= Hash[swatches_with_overrides.map { |s| [s.id, s] }]
end