module Spree::Core::ControllerHelpers::Order
Public Instance Methods
associate_user()
click to toggle source
# File lib/spree/core/controller_helpers/order.rb, line 39 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 end
current_order(options = {})
click to toggle source
The current incomplete order from the guest_token for use in cart and during checkout
# File lib/spree/core/controller_helpers/order.rb, line 17 def current_order(options = {}) should_create = options[:create_order_if_necessary] || false should_build = options[:build_order_if_necessary] || should_create return @current_order if @current_order @current_order = find_order_by_token_or_user(lock: options[:lock]) if should_build && (@current_order.nil? || @current_order.completed?) @current_order = Spree::Order.new(new_order_params) @current_order.user ||= try_spree_current_user # See issue https://github.com/spree/spree/issues/3346 for reasons why this line is here @current_order.created_by ||= try_spree_current_user @current_order.save! if should_create end if @current_order @current_order.record_ip_address(ip_address) return @current_order end end
ip_address()
click to toggle source
# File lib/spree/core/controller_helpers/order.rb, line 54 def ip_address request.remote_ip end
set_current_order()
click to toggle source
# File lib/spree/core/controller_helpers/order.rb, line 46 def set_current_order if try_spree_current_user && current_order try_spree_current_user.orders.by_store(current_store).incomplete.where('id != ?', current_order.id).each do |order| current_order.merge!(order, try_spree_current_user) end end end
Private Instance Methods
current_order_params()
click to toggle source
# File lib/spree/core/controller_helpers/order.rb, line 64 def current_order_params { currency: current_pricing_options.currency, guest_token: cookies.signed[:guest_token], store_id: current_store.id, user_id: try_spree_current_user.try(:id) } end
find_order_by_token_or_user(options = {})
click to toggle source
# File lib/spree/core/controller_helpers/order.rb, line 72 def find_order_by_token_or_user(options = {}) should_lock = options[:lock] || false # Find any incomplete orders for the guest_token order = Spree::Order.incomplete.lock(should_lock).find_by(current_order_params) # Find any incomplete orders for the current user if order.nil? && try_spree_current_user order = last_incomplete_order end order end
last_incomplete_order()
click to toggle source
# File lib/spree/core/controller_helpers/order.rb, line 60 def last_incomplete_order @last_incomplete_order ||= try_spree_current_user.last_incomplete_spree_order(store: current_store) end
new_order_params()
click to toggle source
# File lib/spree/core/controller_helpers/order.rb, line 68 def new_order_params current_order_params.merge(last_ip_address: ip_address) end