Class: Spree::PromotionAction

Inherits:
Base
  • Object
show all
Includes:
Discard::Model, ParanoiaDeprecations
Defined in:
app/models/spree/promotion_action.rb

Overview

Base class for all types of promotion action.

PromotionActions perform the necessary tasks when a promotion is activated by an event and determined to be eligible.

Instance Method Summary collapse

Methods included from ParanoiaDeprecations

#paranoia_delete, #paranoia_destroy

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Spree::Preferences::Preferable

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

Instance Method Details

#perform(_options = {}) ⇒ Object

Note:

This method should be overriden in subclassses.

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

#remove_from(order) ⇒ void

Note:

This method should be overriden in subclassses.

This method returns an undefined value.

Removes the action from an order

Parameters:

  • order (Spree::Order)

    the order to remove the action from



38
39
40
41
42
43
44
45
46
47
# File 'app/models/spree/promotion_action.rb', line 38

def remove_from(order)
  Spree::Deprecation.warn("#{self.class.name.inspect} does not define #remove_from. The default behavior may be incorrect and will be removed in a future version of Solidus.", caller)
  [order, *order.line_items, *order.shipments].each do |item|
    item.adjustments.each do |adjustment|
      if adjustment.source == self
        item.adjustments.destroy(adjustment)
      end
    end
  end
end

#to_partial_pathObject



49
50
51
# File 'app/models/spree/promotion_action.rb', line 49

def to_partial_path
  "spree/admin/promotions/actions/#{model_name.element}"
end