Sha256: 6747328a8edb95f4c1b71a947f234bc00f30ffac76b9423289edb8f2e2e6a6dd

Contents?: true

Size: 829 Bytes

Versions: 21

Compression:

Stored size: 829 Bytes

Contents

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

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

    validates :property, presence: true

    validates :value, db_maximum_length: true

    default_scope { order(:position) }

    self.whitelisted_ransackable_attributes = ['value']

    # virtual attributes for use with AJAX completion stuff
    delegate :name, to: :property, prefix: true, allow_nil: true

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
spree_core-3.1.14 app/models/spree/product_property.rb
spree_core-3.1.13 app/models/spree/product_property.rb
spree_core-3.1.12 app/models/spree/product_property.rb
spree_core-3.1.11 app/models/spree/product_property.rb
spree_core-3.1.10 app/models/spree/product_property.rb
spree_core-3.1.9 app/models/spree/product_property.rb
spree_core-3.1.8 app/models/spree/product_property.rb
spree_core-3.1.7 app/models/spree/product_property.rb
spree_core-3.1.6 app/models/spree/product_property.rb
spree_core-3.1.5 app/models/spree/product_property.rb
spree_core-3.1.4 app/models/spree/product_property.rb
spree_core-3.2.0.rc2 app/models/spree/product_property.rb
spree_core-3.2.0.rc1 app/models/spree/product_property.rb
spree_core-3.1.3 app/models/spree/product_property.rb
spree_core-3.1.2 app/models/spree/product_property.rb
spree_core-3.1.1 app/models/spree/product_property.rb
spree_core-3.1.0 app/models/spree/product_property.rb
spree_core-3.1.0.rc4 app/models/spree/product_property.rb
spree_core-3.1.0.rc3 app/models/spree/product_property.rb
spree_core-3.1.0.rc2 app/models/spree/product_property.rb