Sha256: bfd6834a8ce830f0603c36c772afb8fbc8682734b3c65f6abc0cf42d25e303a4

Contents?: true

Size: 840 Bytes

Versions: 7

Compression:

Stored size: 840 Bytes

Contents

module Spree
  class ProductProperty < Spree::Base
    acts_as_list
    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 :value, length: { maximum: 255 }

    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)
      unless name.blank?
        unless property = Property.find_by(name: name)
          property = Property.create(name: name, presentation: name)
        end
        self.property = property
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_core-1.0.7 app/models/spree/product_property.rb
solidus_core-1.0.6 app/models/spree/product_property.rb
solidus_core-1.0.5 app/models/spree/product_property.rb
solidus_core-1.0.4 app/models/spree/product_property.rb
solidus_core-1.0.3 app/models/spree/product_property.rb
solidus_core-1.0.2 app/models/spree/product_property.rb
solidus_core-1.0.1 app/models/spree/product_property.rb