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

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary (collapse)

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Spree::Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

- (Object) compute_amount(shipment)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'app/models/spree/promotion/actions/free_shipping.rb', line 29

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

- (Object) label

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'app/models/spree/promotion/actions/free_shipping.rb', line 25

def label
  "#{Spree.t(:promotion)} (#{promotion.name})"
end

- (Object) perform(payload = {})

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/spree/promotion/actions/free_shipping.rb', line 5

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

  results = order.shipments.map do |shipment|
    return false if promotion_credit_exists?(shipment)
    shipment.adjustments.create!(
      order: shipment.order,
      amount: compute_amount(shipment),
      source: self,
      promotion_code: promotion_code,
      label: label
    )
    true
  end
  # Did we actually end up applying any adjustments?
  # If so, then this action should be classed as 'successful'
  results.any? { |r| r == true }
end

- (void) remove_from(order)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Removes any adjustments generated by this action from the order's

shipments.

Parameters:

  • order (Spree::Order)

    the order to remove the action from.



37
38
39
40
41
42
43
44
45
# File 'app/models/spree/promotion/actions/free_shipping.rb', line 37

def remove_from(order)
  order.shipments.each do |shipment|
    shipment.adjustments.each do |adjustment|
      if adjustment.source == self
        shipment.adjustments.destroy(adjustment)
      end
    end
  end
end