Class: DeliveryPricingTier

Inherits:
ApplicationRecord show all
Includes:
IdentityCache
Defined in:
app/models/delivery_pricing_tier.rb

Overview

typed: ignore

Schema Information

Table name: delivery_pricing_tiers

id                          :bigint           not null, primary key
delivery_base_fare_cents    :integer          default(0), not null
delivery_base_fare_currency :string(191)      default("THB")
delivery_fee_price_cents    :integer          default(0), not null
free_delivery_radius_in_km  :integer          default(0)
price_currency              :string(191)      default("THB")
start_rate_price_cents      :integer          default(0), not null
subsidize_cents             :integer          default(0), not null
created_at                  :datetime         not null
updated_at                  :datetime         not null
restaurant_id               :bigint

Indexes

delivery_pricing_res_index                     (restaurant_id,start_rate_price_cents) UNIQUE
index_delivery_pricing_tiers_on_restaurant_id  (restaurant_id)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Class Method Details

.default_tierObject

use this class method as AdminSetting.delivery_fee



36
37
38
# File 'app/models/delivery_pricing_tier.rb', line 36

def self.default_tier
  global_scope.order('start_rate_price_cents ASC').first.presence || new
end

.filter_by_total_price(instances, total_price_cents) ⇒ Object



49
50
51
52
# File 'app/models/delivery_pricing_tier.rb', line 49

def self.filter_by_total_price(instances, total_price_cents)
  instances.where('start_rate_price_cents <= ?', total_price_cents)
           .order(start_rate_price_cents: :desc).first.presence || nil
end

Instance Method Details

#to_admin_settingObject



40
41
42
43
44
45
46
47
# File 'app/models/delivery_pricing_tier.rb', line 40

def to_admin_setting
  {
    delivery_fee_currency: price_currency,
    delivery_fee_per_km_in_baht: delivery_fee_price.amount.to_i,
    free_delivery_fee_threshold_in_baht: start_rate_price.amount.to_i,
    delivery_radius: free_delivery_radius_in_km
  }
end