Module: Spree::Order::Checkout

Included in:
Spree::Order
Defined in:
app/models/spree/order/checkout.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'app/models/spree/order/checkout.rb', line 6

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

Instance Method Details

#can_go_to_state?(state) ⇒ Boolean

Returns:

  • (Boolean)


237
238
239
240
# File 'app/models/spree/order/checkout.rb', line 237

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



233
234
235
# File 'app/models/spree/order/checkout.rb', line 233

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

#checkout_stepsObject



215
216
217
218
219
220
221
222
223
# File 'app/models/spree/order/checkout.rb', line 215

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)


225
226
227
# File 'app/models/spree/order/checkout.rb', line 225

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

#passed_checkout_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


229
230
231
# File 'app/models/spree/order/checkout.rb', line 229

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