Module: SpreeCmCommissioner::OptionTypeDecorator

Defined in:
app/models/spree_cm_commissioner/option_type_decorator.rb

Class Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/spree_cm_commissioner/option_type_decorator.rb', line 3

def self.prepended(base)
  base.include SpreeCmCommissioner::ParameterizeName
  base.include SpreeCmCommissioner::OptionTypeAttrType

  base.enum kind: %i[variant product vendor vehicle_type transit]

  base.validates :name, presence: true

  base.validate :kind_has_updated, on: :update, if: :kind_changed?

  base.has_many :variants, through: :products

  base.scope :promoted, -> { where(promoted: true) }
  base.whitelisted_ransackable_attributes = %w[kind]

  def base.amenities
    Spree::OptionType.where(kind: 'vehicle_type', name: 'amenities', presentation: 'Amenities', attr_type: 'amenity').first_or_create
  end

  def base.vehicle
    Spree::OptionType.where(presentation: 'vehicle', attr_type: 'vehicle_id', kind: 'variant',
                            name: 'vehicle'
    ).first_or_create
  end
end