Class: Spree::OptionValue

Inherits:
Object
  • Object
show all
Includes:
Metadata, Metafields, ParameterizableName, TranslatableResource
Defined in:
app/models/spree/option_value.rb

Constant Summary collapse

TRANSLATABLE_FIELDS =
%i[presentation].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metadata

#metadata, #metadata=, #public_metadata=

Class Method Details

.to_tom_select_jsonArray<Hash>

Using map here instead of pluck, as these values are translatable via Mobility gem

Returns:

  • (Array<Hash>)


83
84
85
86
87
88
89
90
# File 'app/models/spree/option_value.rb', line 83

def self.to_tom_select_json
  all.map do |ov|
    {
      id: ov.name,
      name: ov.presentation
    }
  end
end

Instance Method Details

#display_presentationString

Returns the presentation with the option type presentation, eg. “Color: Red”

Returns:

  • (String)


94
95
96
# File 'app/models/spree/option_value.rb', line 94

def display_presentation
  @display_presentation ||= "#{option_type.presentation}: #{presentation}"
end

#label(*args) ⇒ Object

5.5 API naming bridge (DB column rename in 6.0) NOTE: alias_attribute bypasses Mobility’s locale-aware reader/writer, so we define explicit delegating methods instead.



39
40
41
# File 'app/models/spree/option_value.rb', line 39

def label(*args)
  presentation(*args)
end

#label=(value) ⇒ Object



43
44
45
# File 'app/models/spree/option_value.rb', line 43

def label=(value)
  self.presentation = value
end