Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Spree
- class Order < ActiveRecord::Base
- module DefaultCheckout
- def self.included(klass)
- klass.class_eval do
- delegate :next, :next!, :to => :machine
- end
- end
- def machine
- order = self
- @machine ||= Spree::Order::Checkout::Machine.new(order, :initial => "cart") do
- order.transitions.each { |attrs| transition(attrs) }
- event :cancel do
- transition :to => 'canceled', :if => :allow_cancel?
- end
- event :return do
- transition :to => 'returned', :from => 'awaiting_return'
- end
- event :resume do
- transition :to => 'resumed', :from => 'canceled', :if => :allow_resume?
- end
- event :authorize_return do
- transition :to => 'awaiting_return'
- end
- before_transition :to => 'complete' do |order|
- begin
- order.process_payments!
- rescue Core::GatewayError
- !!Spree::Config[:allow_checkout_on_gateway_error]
- end
- end
- before_transition :to => 'delivery' do
- order.remove_invalid_shipments!
- end
- # after_transition :to => 'complete', :do => :finalize!
- # after_transition :to => 'delivery', :do => :create_tax_charge!
- # after_transition :to => 'payment', :do => :create_shipment!
- # after_transition :to => 'resumed', :do => :after_resume
- # after_transition :to => 'canceled', :do => :after_cancel
- # Persist the state on the order
- after_transition do
- order.state = order.machine.state
- order.save
- end
- end
- end
- def transitions
- [
- { "cart" => "address", :on => :next },
- { "address" => "delivery", :on => :next },
- { "delivery" => "payment", :on => :next, :if => :payment_required? },
- { "payment" => "confirm", :on => :next, :if => :confirmation_required? },
- { "payment" => "complete", :on => :next },
- { "delivery" => "complete", :on => :next },
- { "confirm" => "complete", :on => :next }
- ]
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment