Class: Spree::PromotionAction

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/promotion_action.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.additional_permitted_attributesObject

Per-subclass permitted attributes beyond ‘type` and `preferences`. Override in STI subclasses that accept nested attributes (e.g. CreateLineItems needs `promotion_action_line_items_attributes`, CreateAdjustment needs `calculator_type` + `calculator_attributes`). The Admin API merges these into its `params.permit(…)` allowlist.



20
21
22
# File 'app/models/spree/promotion_action.rb', line 20

def self.additional_permitted_attributes
  []
end

.human_descriptionObject



43
44
45
# File 'app/models/spree/promotion_action.rb', line 43

def self.human_description
  Spree.t("promotion_action_types.#{api_type}.description", default: '')
end

.human_nameObject



39
40
41
# File 'app/models/spree/promotion_action.rb', line 39

def self.human_name
  Spree.t("promotion_action_types.#{api_type}.name", default: api_type.titleize)
end

Instance Method Details

#free_shipping?Boolean

Returns true if the promotion action is a free shipping action

Returns:

  • (Boolean)


35
36
37
# File 'app/models/spree/promotion_action.rb', line 35

def free_shipping?
  type == 'Spree::Promotion::Actions::FreeShipping'
end

#human_descriptionObject



48
# File 'app/models/spree/promotion_action.rb', line 48

def human_description = self.class.human_description

#human_nameObject



47
# File 'app/models/spree/promotion_action.rb', line 47

def human_name = self.class.human_name

#keyString

Returns the key of the promotion action

Returns:

  • (String)

    eg. free_shipping



53
54
55
# File 'app/models/spree/promotion_action.rb', line 53

def key
  self.class.api_type
end

#perform(_options = {}) ⇒ Object

This method should be overridden in subclass Updates the state of the order or performs some other action depending on the subclass options will contain the payload from the event that activated the promotion. This will include the key :user which allows user based actions to be performed in addition to actions on the order



28
29
30
# File 'app/models/spree/promotion_action.rb', line 28

def perform(_options = {})
  raise 'perform should be implemented in a sub-class of PromotionAction'
end