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

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

Instance Method Summary collapse

Instance Method Details

#associate_userObject


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

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 = {}) ⇒ Object

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


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/spree/core/controller_helpers/order.rb', line 29

def current_order(options = {})
  options[:create_order_if_necessary] ||= false

  return @current_order if @current_order

  @current_order = find_order_by_token_or_user(options, true)

  if options[:create_order_if_necessary] && (@current_order.nil? || @current_order.completed?)
    @current_order = Spree::Order.create!(current_order_params)
    @current_order.associate_user! try_spree_current_user if try_spree_current_user
  end

  if @current_order
    @current_order.last_ip_address = ip_address
    return @current_order
  end
end

#ip_addressObject


62
63
64
# File 'lib/spree/core/controller_helpers/order.rb', line 62

def ip_address
  request.remote_ip
end

#set_current_orderObject


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

def set_current_order
  if try_spree_current_user && current_order
    try_spree_current_user.orders.incomplete.where('id != ?', current_order.id).each do |order|
      current_order.merge!(order, try_spree_current_user)
    end
  end
end

#simple_current_orderObject

Used in the link_to_cart helper.


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spree/core/controller_helpers/order.rb', line 15

def simple_current_order
  return @simple_current_order if @simple_current_order

  @simple_current_order = find_order_by_token_or_user

  if @simple_current_order
    @simple_current_order.last_ip_address = ip_address
    return @simple_current_order
  else
    @simple_current_order = Spree::Order.new
  end
end