Class: AddOns::Pricing

Inherits:
ApplicationRecord show all
Extended by:
Enumerize
Includes:
IdentityCache
Defined in:
app/models/add_ons/pricing.rb

Overview

Schema Information

Table name: add_on_pricings

id             :bigint           not null, primary key
price_cents    :integer          default(0), not null
price_currency :string(191)      default("THB"), not null
pricing_type   :string(191)
created_at     :datetime         not null
updated_at     :datetime         not null
add_on_id      :bigint

Indexes

index_add_on_pricings_on_add_on_id  (add_on_id)

Foreign Keys

fk_rails_...  (add_on_id => add_ons.id)

Constant Summary collapse

PRICING_TYPE_PER_ITEM =
'per_item'
PRICING_TYPE_PER_PERSON =
'per_person'
PRICING_TYPES =
[PRICING_TYPE_PER_ITEM, PRICING_TYPE_PER_PERSON].freeze
DEFAULT_CURRENCY =
'THB'
UNLIMITED =

1 milion means unlimited

1_000_000

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Class Method Details

.decide_add_on_quantity(add_on, adult, quantity) ⇒ Integer

Decide the quantity of add-on based on pricing type If pricing type is per_person, return adult If pricing type is per_item, return quantity

Parameters:

Returns:

  • (Integer)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/add_ons/pricing.rb', line 54

def decide_add_on_quantity(add_on, adult, quantity)
  return 0 if add_on.blank?
  return 0 unless add_on.is_a?(AddOns::AddOn)

  case add_on.pricing.pricing_type
  when AddOns::Pricing::PRICING_TYPE_PER_PERSON
    adult
  when AddOns::Pricing::PRICING_TYPE_PER_ITEM
    quantity
  else
    APMErrorHandler.report("Unknown add-on pricing type: #{add_on.pricing.pricing_type}", { add_on_id: add_on.id })
    0
  end
end

Instance Method Details

#per_item?Boolean

Instance Methods

Returns:

  • (Boolean)


71
72
73
# File 'app/models/add_ons/pricing.rb', line 71

def per_item?
  pricing_type == PRICING_TYPE_PER_ITEM
end