Sha256: e5e639e6ee286bf6a3bafc5a0e78b647d8f840c37322df76be93eb127ae46c48

Contents?: true

Size: 824 Bytes

Versions: 4

Compression:

Stored size: 824 Bytes

Contents

module Spree
  module CurrentOrder

    # This should be overridden by an auth-related extension which would then have the opporutnity to associate the new order with the
    # current user before saving.
    def before_save_new_order
    end

    # The current incomplete order from the session for use in cart and during checkout
    def current_order(create_order_if_necessary = false)
      return @current_order if @current_order
      @current_order ||= Order.find_by_id(session[:order_id], :include => :adjustments)
      if create_order_if_necessary and (@current_order.nil? or @current_order.completed?)
        @current_order = Order.new
        before_save_new_order
        @current_order.save!
      end
      session[:order_id] = @current_order ? @current_order.id : nil
      @current_order
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_core-0.30.2 lib/spree/current_order.rb
spree_core-0.40.0 lib/spree/current_order.rb
spree_core-0.30.1 lib/spree/current_order.rb
spree_core-0.30.0 lib/spree/current_order.rb