Class: SpreeCmCommissioner::PricingActions::CreateRouteAdjustments

Inherits:
SpreeCmCommissioner::PricingAction show all
Defined in:
app/models/spree_cm_commissioner/pricing_actions/create_route_adjustments.rb

Instance Method Summary collapse

Methods inherited from SpreeCmCommissioner::PricingAction

available_calculator_types, #compute_amount

Instance Method Details

#preview(options = {}) ⇒ 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
# File 'app/models/spree_cm_commissioner/pricing_actions/create_route_adjustments.rb', line 4

def preview(options = {})
  order_context = options[:order_context]
  line_item_contexts = Array(options[:line_item_contexts])

  return [] if pricing_rules.blank?
  return [] if line_item_contexts.blank?

  eligible_guest_contexts = collect_unique_eligible_guest_contexts(line_item_contexts)
  return [] if eligible_guest_contexts.empty?

  total_amount = compute_total_amount(line_item_contexts, eligible_guest_contexts)
  return [] if total_amount.zero?

  [
    PricingModels::PreviewAdjustment.new(
      label: label,
      amount: total_amount,
      action_type: 'create_route_adjustments',
      pricing_action: self,
      adjustable_type: 'Spree::Order',
      adjustable_id: order_context.id,
      line_item_id: nil,
      guest_ids: eligible_guest_contexts.map(&:id).compact
    )
  ]
end