Class: SpreeCmCommissioner::Integrations::VireakBuntham::Polling::SyncNationalityPricing

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_nationality_pricing.rb

Overview

SyncNationalityPricing — applies VET local/foreigner pricing to a Route.

Per PRICING_COMPLETE.md:

variant.price     = effective_local_price   (already updated by sync_price)
foreigner_delta   = effective_foreigner - effective_local

One PricingModel per vendor; one PricingRuleGroup per route (so each route gets an independent FlatRate calculator). Order time evaluates the rule group via NationalityGroup → CreateGuestAdjustments → FlatRate(amount).

Skipped only when no foreigner price is provided (foreigner_price <= 0). A negative delta is valid (foreigner gets a discount).

Constant Summary collapse

PRICING_MODEL_NAME =
'VireakBuntham Nationality Pricing'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(route:, vendor:, local_price:, foreigner_price:) ⇒ SyncNationalityPricing

Returns a new instance of SyncNationalityPricing.



17
18
19
20
21
22
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_nationality_pricing.rb', line 17

def initialize(route:, vendor:, local_price:, foreigner_price:)
  @route = route
  @vendor = vendor
  @local_price = local_price.to_f
  @foreigner_price = foreigner_price.to_f
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_nationality_pricing.rb', line 24

def call
  return if @foreigner_price <= 0
  return if @route.blank? || @vendor.blank?

  delta = @foreigner_price - @local_price

  model = find_or_create_pricing_model
  group = find_or_create_rule_group(model)
  action = find_or_create_action(group, delta)

  action.calculator.update!(preferred_amount: delta)
  find_or_create_model_route(model)
end