Sha256: a582ac421a297fc16accdbd80746277f0c41c22d8c0cbc11fde34bd339cd5592

Contents?: true

Size: 949 Bytes

Versions: 7

Compression:

Stored size: 949 Bytes

Contents

module Spree
  class ProductProperty < Spree::Base
    acts_as_list scope: :product

    belongs_to :product, touch: true, class_name: 'Spree::Product', inverse_of: :product_properties
    belongs_to :property, class_name: 'Spree::Property', inverse_of: :product_properties

    validates :property, presence: true

    validates_with Spree::Validations::DbMaximumLengthValidator, field: :value

    default_scope { order("#{self.table_name}.position") }

    self.whitelisted_ransackable_attributes = ['value']

    # virtual attributes for use with AJAX completion stuff
    def property_name
      property.name if property
    end

    def property_name=(name)
      if name.present?
        # don't use `find_by :name` to workaround globalize/globalize#423 bug
        property = Property.where(name: name).first ||
                   Property.create(name: name, presentation: name)
        self.property = property
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spree_core-3.0.10 app/models/spree/product_property.rb
spree_core-3.0.9 app/models/spree/product_property.rb
spree_core-3.0.8 app/models/spree/product_property.rb
spree_core-3.0.7 app/models/spree/product_property.rb
spree_core-3.0.6.1 app/models/spree/product_property.rb
spree_core-3.0.6 app/models/spree/product_property.rb
spree_core-3.0.5 app/models/spree/product_property.rb