Module: Spree::Core::ControllerHelpers::Order
- Defined in:
- lib/spree/core/controller_helpers/order.rb
Class Method Summary collapse
Instance Method Summary collapse
- #associate_user ⇒ Object
- #current_currency ⇒ Object
-
#current_order(options = {}) ⇒ Object
The current incomplete order from the session for use in cart and during checkout.
- #ip_address ⇒ Object
- #set_current_order ⇒ Object
-
#simple_current_order ⇒ Object
Used in the link_to_cart helper.
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/spree/core/controller_helpers/order.rb', line 5 def self.included(base) base.class_eval do helper_method :simple_current_order helper_method :current_order helper_method :current_currency before_filter :set_current_order end end |
Instance Method Details
#associate_user ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/spree/core/controller_helpers/order.rb', line 51 def associate_user @order ||= current_order if try_spree_current_user && @order @order.associate_user!(try_spree_current_user) if @order.user.blank? || @order.email.blank? end session[:guest_token] = nil end |
#current_currency ⇒ Object
71 72 73 |
# File 'lib/spree/core/controller_helpers/order.rb', line 71 def current_currency Spree::Config[:currency] end |
#current_order(options = {}) ⇒ Object
The current incomplete order from the session for use in cart and during checkout
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/spree/core/controller_helpers/order.rb', line 20 def current_order( = {}) [:create_order_if_necessary] ||= false [:lock] ||= false return @current_order if @current_order if session[:order_id] current_order = Spree::Order.includes(:adjustments).lock([:lock]).find_by(id: session[:order_id], currency: current_currency) @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) @current_order.user ||= try_spree_current_user # See issue #3346 for reasons why this line is here @current_order.created_by ||= try_spree_current_user @current_order.save! # make sure the user has permission to access the order (if they are a guest) if try_spree_current_user.nil? session[:access_token] = @current_order.token end end if @current_order @current_order.last_ip_address = ip_address session[:order_id] = @current_order.id return @current_order end end |
#ip_address ⇒ Object
75 76 77 |
# File 'lib/spree/core/controller_helpers/order.rb', line 75 def ip_address request.remote_ip end |
#set_current_order ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/spree/core/controller_helpers/order.rb', line 60 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 && last_incomplete_order && current_order != last_incomplete_order current_order.merge!(last_incomplete_order, user) end end end |