Class: Spree::Property

Inherits:
Object
  • Object
show all
Includes:
DisplayOn, FilterParam, Metadata, ParameterizableName, TranslatableResource, UniqueName, Webhooks::HasWebhooks
Defined in:
app/models/spree/property.rb

Constant Summary collapse

TRANSLATABLE_FIELDS =
i[presentation].freeze
KIND_OPTIONS =
{ short_text: 0, long_text: 1, number: 2, rich_text: 3 }.freeze
DEPENDENCY_UPDATE_FIELDS =
[:presentation, :name, :kind, :filterable, :display_on, :position].freeze

Constants included from DisplayOn

DisplayOn::DISPLAY

Instance Method Summary collapse

Instance Method Details

#kind_to_metafield_typeString

Returns the metafield type for the property kind

Returns:

  • (String)

    eg. ‘Spree::Metafields::ShortText’



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/spree/property.rb', line 55

def kind_to_metafield_type
  case kind
  when 'short_text'
    'Spree::Metafields::ShortText'
  when 'long_text'
    'Spree::Metafields::LongText'
  when 'number'
    'Spree::Metafields::Number'
  when 'rich_text'
    'Spree::Metafields::RichText'
  else
    'Spree::Metafields::ShortText'
  end
end

#uniq_values(product_properties_scope: nil) ⇒ Object



45
46
47
48
49
50
51
# File 'app/models/spree/property.rb', line 45

def uniq_values(product_properties_scope: nil)
  with_uniq_values_cache_key(product_properties_scope) do
    properties = product_properties
    properties = properties.where(id: product_properties_scope) if product_properties_scope.present?
    properties.where.not(value: [nil, '']).pluck(:filter_param, :value).uniq
  end
end