Class: Spree::PromotionAction
- Inherits:
-
Object
- Object
- Spree::PromotionAction
- Defined in:
- app/models/spree/promotion_action.rb
Direct Known Subclasses
Spree::Promotion::Actions::CreateAdjustment, Spree::Promotion::Actions::CreateItemAdjustments, Spree::Promotion::Actions::CreateLineItems, Spree::Promotion::Actions::FreeShipping
Class Method Summary collapse
-
.additional_permitted_attributes ⇒ Object
Per-subclass permitted attributes beyond ‘type` and `preferences`.
- .human_description ⇒ Object
- .human_name ⇒ Object
Instance Method Summary collapse
-
#free_shipping? ⇒ Boolean
Returns true if the promotion action is a free shipping action.
- #human_description ⇒ Object
- #human_name ⇒ Object
-
#key ⇒ String
Returns the key of the promotion action.
-
#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.
Class Method Details
.additional_permitted_attributes ⇒ Object
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_description ⇒ Object
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_name ⇒ Object
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
35 36 37 |
# File 'app/models/spree/promotion_action.rb', line 35 def free_shipping? type == 'Spree::Promotion::Actions::FreeShipping' end |
#human_description ⇒ Object
48 |
# File 'app/models/spree/promotion_action.rb', line 48 def human_description = self.class.human_description |
#human_name ⇒ Object
47 |
# File 'app/models/spree/promotion_action.rb', line 47 def human_name = self.class.human_name |
#key ⇒ String
Returns the key of the promotion action
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( = {}) raise 'perform should be implemented in a sub-class of PromotionAction' end |