Class: SpreeCmCommissioner::PricingActions::CreateLineItemAdjustments

Inherits:
SpreeCmCommissioner::PricingAction show all
Defined in:
app/models/spree_cm_commissioner/pricing_actions/create_line_item_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
# File 'app/models/spree_cm_commissioner/pricing_actions/create_line_item_adjustments.rb', line 4

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

  return [] if line_item_contexts.blank?

  line_item_contexts.filter_map do |line_item_context|
    amount = compute_amount(line_item_context)
    next nil if amount.zero?

    PricingModels::PreviewAdjustment.new(
      label: label,
      amount: amount,
      action_type: 'create_line_item_adjustments',
      pricing_action: self,
      adjustable_type: 'Spree::LineItem',
      adjustable_id: line_item_context.id,
      line_item_id: line_item_context.id,
      guest_ids: []
    )
  end
end