Module: Spree::Core::StateMachines::Order

Defined in:
app/models/spree/core/state_machines/order.rb,
app/models/spree/core/state_machines/order/class_methods.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



7
8
9
# File 'app/models/spree/core/state_machines/order.rb', line 7

def self.included(klass)
  klass.extend ClassMethods
end

Instance Method Details

#can_go_to_state?(state) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'app/models/spree/core/state_machines/order.rb', line 34

def can_go_to_state?(state)
  return false unless has_checkout_step?(self.state) && has_checkout_step?(state)

  checkout_step_index(state) > checkout_step_index(self.state)
end

#checkout_step_index(step) ⇒ Object



30
31
32
# File 'app/models/spree/core/state_machines/order.rb', line 30

def checkout_step_index(step)
  checkout_steps.index(step).to_i
end

#checkout_stepsObject



11
12
13
14
15
16
17
18
19
20
# File 'app/models/spree/core/state_machines/order.rb', line 11

def checkout_steps
  steps = self.class.checkout_steps.each_with_object([]) { |(step, options), checkout_steps|
    next if options.include?(:if) && !options[:if].call(self)

    checkout_steps << step
  }.map(&:to_s)
  # Ensure there is always a complete step
  steps << "complete" unless steps.include?("complete")
  steps
end

#has_checkout_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/spree/core/state_machines/order.rb', line 22

def has_checkout_step?(step)
  step.present? && checkout_steps.include?(step)
end

#passed_checkout_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/spree/core/state_machines/order.rb', line 26

def passed_checkout_step?(step)
  has_checkout_step?(step) && checkout_step_index(step) < checkout_step_index(state)
end