Sha256: 261225ad60350f5e001bb45dded14a339778828b352624da6847fa7dc6b62fde

Contents?: true

Size: 938 Bytes

Versions: 54

Compression:

Stored size: 938 Bytes

Contents

module Spree
  class OptionType < Spree::Base
    acts_as_list

    with_options dependent: :destroy, inverse_of: :option_type do
      has_many :option_values, -> { order(:position) }
      has_many :product_option_types
    end

    has_many :products, through: :product_option_types

    has_many :option_type_prototypes, class_name: 'Spree::OptionTypePrototype'
    has_many :prototypes, through: :option_type_prototypes, class_name: 'Spree::Prototype'

    with_options presence: true do
      validates :name, uniqueness: { case_sensitive: false, allow_blank: true }
      validates :presentation
    end

    default_scope { order(:position) }

    accepts_nested_attributes_for :option_values, reject_if: ->(ov) { ov[:name].blank? || ov[:presentation].blank? }, allow_destroy: true

    after_touch :touch_all_products

    private

    def touch_all_products
      products.update_all(updated_at: Time.current)
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/models/spree/option_type.rb
spree_core-4.0.8 app/models/spree/option_type.rb
spree_core-3.7.14.1 app/models/spree/option_type.rb
spree_core-4.0.7.1 app/models/spree/option_type.rb
spree_core-4.0.7 app/models/spree/option_type.rb
spree_core-3.7.14 app/models/spree/option_type.rb
spree_core-4.0.6 app/models/spree/option_type.rb
spree_core-3.7.13 app/models/spree/option_type.rb
spree_core-4.0.5 app/models/spree/option_type.rb
spree_core-3.7.12 app/models/spree/option_type.rb
spree_core-4.0.4 app/models/spree/option_type.rb
spree_core-3.7.11 app/models/spree/option_type.rb
spree_core-3.4.6 app/models/spree/option_type.rb
spree_core-3.7.10 app/models/spree/option_type.rb
spree_core-4.0.3 app/models/spree/option_type.rb
spree_core-3.7.9 app/models/spree/option_type.rb
spree_core-4.0.2 app/models/spree/option_type.rb
spree_core-3.7.8 app/models/spree/option_type.rb
spree_core-4.0.1 app/models/spree/option_type.rb
spree_core-3.7.7 app/models/spree/option_type.rb