Sha256: 82d0335204a65f88d437cede58aec879e321e820c9be5f56bffa84399db1f699

Contents?: true

Size: 1.03 KB

Versions: 34

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Spree
  class OptionValue < Spree::Base
    belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :option_values
    acts_as_list scope: :option_type

    has_many :option_values_variants, dependent: :destroy
    has_many :variants, through: :option_values_variants

    validates :name, presence: true, uniqueness: { scope: :option_type_id, allow_blank: true }
    validates :presentation, presence: true

    after_save :touch, if: :saved_changes?
    after_touch :touch_all_variants

    delegate :name, :presentation, to: :option_type, prefix: :option_type

    self.whitelisted_ransackable_attributes = ['presentation']

    # Updates the updated_at column on all the variants associated with this
    # option value.
    def touch_all_variants
      variants.find_each(&:touch)
    end

    # @return [String] a string representation of all option value and its
    #   option type
    def presentation_with_option_type
      "#{option_type.presentation} - #{presentation}"
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
solidus_core-2.8.6 app/models/spree/option_value.rb
solidus_core-2.6.6 app/models/spree/option_value.rb
solidus_core-2.7.4 app/models/spree/option_value.rb
solidus_core-2.8.5 app/models/spree/option_value.rb
solidus_core-2.7.3 app/models/spree/option_value.rb
solidus_core-2.6.5 app/models/spree/option_value.rb
solidus_core-2.8.4 app/models/spree/option_value.rb
solidus_core-2.8.3 app/models/spree/option_value.rb
solidus_core-2.7.2 app/models/spree/option_value.rb
solidus_core-2.6.4 app/models/spree/option_value.rb
solidus_core-2.8.2 app/models/spree/option_value.rb
solidus_core-2.8.1 app/models/spree/option_value.rb
solidus_core-2.6.3 app/models/spree/option_value.rb
solidus_core-2.8.0 app/models/spree/option_value.rb
solidus_core-2.7.1 app/models/spree/option_value.rb
solidus_core-2.6.2 app/models/spree/option_value.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 app/models/spree/option_value.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 app/models/spree/option_value.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 app/models/spree/option_value.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 app/models/spree/option_value.rb