Class: ProductTemplates::SwatchesViewModel
- Inherits:
-
ProductViewModel
- Object
- ProductViewModel
- ProductTemplates::SwatchesViewModel
- Includes:
- OptionSetViewModel
- Defined in:
- app/view_models/workarea/storefront/product_templates/swatches_view_model.rb
Instance Method Summary collapse
- #browse_link_options ⇒ Object
- #browse_swatch_option ⇒ Object
- #current_browse_selection ⇒ Object
- #current_browse_selection?(selection) ⇒ Boolean
- #display_browse_swatches? ⇒ Boolean
- #images_by_option ⇒ Object
- #swatches_by_option ⇒ Object
Instance Method Details
#browse_link_options ⇒ Object
19 20 21 22 |
# File 'app/view_models/workarea/storefront/product_templates/swatches_view_model.rb', line 19 def return super unless current_browse_selection.present? super.merge(browse_swatch_option.slug => current_browse_selection) end |
#browse_swatch_option ⇒ Object
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, ) end |
#current_browse_selection ⇒ Object
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? [browse_swatch_option.slug] end |
#current_browse_selection?(selection) ⇒ 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
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_option ⇒ Object
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_option ⇒ Object
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 |