Module: SpreeCmCommissioner::ProductDecorator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/spree_cm_commissioner/product_decorator.rb', line 4

def self.prepended(base)
  base.include SpreeCmCommissioner::ProductType
  base.include SpreeCmCommissioner::KycBitwise
  base.include SpreeCmCommissioner::Metafield
  base.include SpreeCmCommissioner::TenantUpdatable
  base.include SpreeCmCommissioner::RouteType

  base.has_many :variant_kind_option_types, -> { where(kind: :variant).order(:position) },
                through: :product_option_types, source: :option_type

  base.has_many :product_kind_option_types, -> { where(kind: :product).order(:position) },
                through: :product_option_types, source: :option_type

  base.has_many :promoted_option_types, -> { where(promoted: true).order(:position) },
                through: :product_option_types, source: :option_type

  base.has_many :option_values, through: :option_types
  base.has_many :prices_including_master, lambda {
                                            order('spree_variants.position, spree_variants.id, currency')
                                          }, source: :prices, through: :variants_including_master

  base.has_many :homepage_section_relatables,
                class_name: 'SpreeCmCommissioner::HomepageSectionRelatable',
                dependent: :destroy, as: :relatable

  # after finish purchase an order, user must complete these steps
  base.has_many :product_completion_steps, class_name: 'SpreeCmCommissioner::ProductCompletionStep', dependent: :destroy

  base.has_one :default_state, through: :vendor
  base.has_one :google_wallet, class_name: 'SpreeCmCommissioner::GoogleWallet', dependent: :destroy

  base.has_many :complete_line_items, through: :classifications, source: :line_items
  base.has_many :guests, through: :line_items

  base.has_many :product_places, class_name: 'SpreeCmCommissioner::ProductPlace', dependent: :destroy
  base.has_many :places, through: :product_places
  base.has_many :product_dynamic_fields, class_name: 'SpreeCmCommissioner::ProductDynamicField', dependent: :destroy
  base.has_many :dynamic_fields, through: :product_dynamic_fields, class_name: 'SpreeCmCommissioner::DynamicField'

  base.has_one :venue, -> { where(type: :venue) }, class_name: 'SpreeCmCommissioner::ProductPlace', dependent: :destroy

  base.accepts_nested_attributes_for :product_places, allow_destroy: true

  base.has_one :trip, class_name: 'SpreeCmCommissioner::Trip', dependent: :destroy

  base.belongs_to :event, class_name: 'Spree::Taxon', optional: true

  base.scope :min_price, lambda { |vendor|
    joins(:prices_including_master)
      .where(vendor_id: vendor.id, product_type: vendor.primary_product_type)
      .minimum('spree_prices.price').to_f
  }

  base.scope :max_price, lambda { |vendor|
    joins(:prices_including_master)
      .where(vendor_id: vendor.id, product_type: vendor.primary_product_type)
      .maximum('spree_prices.price').to_f
  }
  base.scope :subscribable, -> { where(subscribable: 1) }

  base.before_validation :set_event_id

  base.validate :validate_event_taxons, if: -> { taxons.event.present? }

  base.validate :validate_product_date, if: -> { available_on.present? && discontinue_on.present? }

  base.validates :commission_rate, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }, allow_nil: true

  base.whitelisted_ransackable_attributes = %w[description name slug discontinue_on status vendor_id short_name route_type]

  base.after_update :update_variants_vendor_id, if: :saved_change_to_vendor_id?
  base.after_update :sync_event_id_to_children, if: :saved_change_to_event_id?

  base.enum purchasable_on: { both: 0, web: 1, app: 2 }

  base.accepts_nested_attributes_for :trip, allow_destroy: true

  base.multi_tenant :tenant, class_name: 'SpreeCmCommissioner::Tenant'
  base.before_save :set_tenant
end

Instance Method Details

#ticket_urlObject



85
86
87
# File 'app/models/spree_cm_commissioner/product_decorator.rb', line 85

def ticket_url
  "#{Spree::Store.default.formatted_url}/tickets/#{slug}"
end