Module: Spree::Core::ControllerHelpers::Order

Extended by:
ActiveSupport::Concern
Includes:
Pricing
Defined in:
lib/spree/core/controller_helpers/order.rb

Instance Method Summary collapse

Methods included from Pricing

#current_pricing_options

Instance Method Details

#associate_userObject



39
40
41
42
43
44
# File 'lib/spree/core/controller_helpers/order.rb', line 39

def associate_user
  @order ||= current_order
  if spree_current_user && @order
    @order.associate_user!(spree_current_user) if @order.user.blank? || @order.email.blank?
  end
end

#current_order(options = {}) ⇒ Object

The current incomplete order from the guest_token for use in cart and during checkout



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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 ||= spree_current_user
    # See issue https://github.com/spree/spree/issues/3346 for reasons why this line is here
    @current_order.created_by ||= 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_addressObject



54
55
56
# File 'lib/spree/core/controller_helpers/order.rb', line 54

def ip_address
  request.remote_ip
end

#set_current_orderObject



46
47
48
49
50
51
52
# File 'lib/spree/core/controller_helpers/order.rb', line 46

def set_current_order
  if spree_current_user && current_order
    spree_current_user.orders.by_store(current_store).incomplete.where('id != ?', current_order.id).find_each do |order|
      current_order.merge!(order, spree_current_user)
    end
  end
end