Module: Spree::Core::CurrentOrder
- Defined in:
- lib/spree/core/current_order.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#after_save_new_order ⇒ Object
This should be overridden by an auth-related extension which would then have the opporutnity to store tokens, etc.
-
#before_save_new_order ⇒ Object
This should be overridden by an auth-related extension which would then have the opportunity to associate the new order with the # current user before saving.
-
#current_order(create_order_if_necessary = false) ⇒ Object
The current incomplete order from the session for use in cart and during checkout.
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 |
# File 'lib/spree/core/current_order.rb', line 4 def self.included(base) base.class_eval do helper_method :current_order end end |
Instance Method Details
#after_save_new_order ⇒ Object
This should be overridden by an auth-related extension which would then have the opporutnity to store tokens, etc. in the session # after saving.
17 18 |
# File 'lib/spree/core/current_order.rb', line 17 def after_save_new_order end |
#before_save_new_order ⇒ Object
This should be overridden by an auth-related extension which would then have the opportunity to associate the new order with the # current user before saving.
12 13 |
# File 'lib/spree/core/current_order.rb', line 12 def before_save_new_order end |
#current_order(create_order_if_necessary = false) ⇒ Object
The current incomplete order from the session for use in cart and during checkout
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spree/core/current_order.rb', line 21 def current_order(create_order_if_necessary = false) return @current_order if @current_order if session[:order_id] current_order = Spree::Order.find_by_id(session[:order_id], :include => :adjustments) @current_order = current_order unless current_order.try(:completed?) end if create_order_if_necessary and (@current_order.nil? or @current_order.completed?) @current_order = Spree::Order.new before_save_new_order @current_order.save! after_save_new_order end session[:order_id] = @current_order ? @current_order.id : nil @current_order end |