Class: Spree::Promotion::Actions::FreeShipping

Inherits:
Spree::PromotionAction show all
Includes:
AdjustmentSource
Defined in:
app/models/spree/promotion/actions/free_shipping.rb

Instance Method Summary collapse

Methods inherited from Spree::PromotionAction

#free_shipping?, #human_description, #human_name, #key

Instance Method Details

#compute_amount(shipment) ⇒ Object



13
14
15
# File 'app/models/spree/promotion/actions/free_shipping.rb', line 13

def compute_amount(shipment)
  shipment.cost * -1
end

#create_adjustment(order, adjustable, included = false) ⇒ Object

we need to persist 0 amount adjustment



18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/spree/promotion/actions/free_shipping.rb', line 18

def create_adjustment(order, adjustable, included = false)
  amount = compute_amount(adjustable)

  adjustments.new(
    adjustable: adjustable,
    amount: amount,
    included: included,
    label: label,
    order: order
  ).save
end

#perform(payload = {}) ⇒ Object



7
8
9
10
11
# File 'app/models/spree/promotion/actions/free_shipping.rb', line 7

def perform(payload = {})
  order = payload[:order]

  create_unique_adjustments(order, order.shipments)
end