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


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

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_currencyObject


67
68
69
# File 'lib/spree/core/controller_helpers/order.rb', line 67

def current_currency
  Spree::Config[:currency]
end

#current_order(options = {}) ⇒ Object

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


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

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.new(current_order_params)
    @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!
  end

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

#ip_addressObject


71
72
73
# File 'lib/spree/core/controller_helpers/order.rb', line 71

def ip_address
  request.remote_ip
end

#set_current_orderObject


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

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.


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

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