Module: Spree::Core::ControllerHelpers::Order
- Included in:
- StoreController
- Defined in:
- lib/spree/core/controller_helpers/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.
- #associate_user ⇒ Object
-
#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.
- #set_current_order ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/spree/core/controller_helpers/order.rb', line 5 def self.included(base) base.class_eval do helper_method :current_order before_filter :set_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.
19 20 |
# File 'lib/spree/core/controller_helpers/order.rb', line 19 def after_save_new_order end |
#associate_user ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/spree/core/controller_helpers/order.rb', line 42 def associate_user @order ||= current_order if try_spree_current_user && @order if @order.user.blank? || @order.email.blank? @order.associate_user!(try_spree_current_user) end end # This will trigger any "first order" promotions to be triggered # Assuming of course that this session variable was set correctly in # the authentication provider's registrations controller if session[:spree_user_signup] fire_event('spree.user.signup', :user => try_spree_current_user, :order => current_order(true)) end session[:guest_token] = nil session[:spree_user_signup] = nil 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.
14 15 |
# File 'lib/spree/core/controller_helpers/order.rb', line 14 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/spree/core/controller_helpers/order.rb', line 23 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_and_currency(session[:order_id], current_currency, :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(currency: current_currency) before_save_new_order @current_order.save! after_save_new_order end if @current_order @current_order.last_ip_address = ip_address session[:order_id] = @current_order.id return @current_order end end |
#set_current_order ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/spree/core/controller_helpers/order.rb', line 61 def set_current_order if user = try_spree_current_user last_incomplete_order = user.last_incomplete_spree_order if session[:order_id].nil? && last_incomplete_order session[:order_id] = last_incomplete_order.id elsif current_order(true) && last_incomplete_order && current_order != last_incomplete_order current_order.merge!(last_incomplete_order) end end end |