Module: Spree::Core::ControllerHelpers

Included in:
BaseController
Defined in:
lib/spree/core/controller_helpers.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#titleObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/spree/core/controller_helpers.rb', line 38

def title
  title_string = @title.present? ? @title : accurate_title
  if title_string.present?
    if Spree::Config[:always_put_site_name_in_title]
      [default_title, title_string].join(' - ')
    else
      title_string
    end
  else
    default_title
  end
end

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/spree/core/controller_helpers.rb', line 6

def self.included(base)
  base.class_eval do
    include Spree::Core::CurrentOrder
    include Spree::Core::RespondWith
    include SslRequirement

    helper_method :title
    helper_method :title=
    helper_method :accurate_title
    helper_method :current_order
    helper_method :try_spree_current_user

    before_filter :set_user_language
    before_filter :set_current_order

    rescue_from CanCan::AccessDenied do |exception|
      return unauthorized
    end

    layout :get_layout
  end
end

Instance Method Details

#associate_userObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/spree/core/controller_helpers.rb', line 51

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

  # This will trigger any "first order" promotions to be triggered
  # Assuming of course that this session variable was set correctly in
  # the authentication provider's registrations controller
  if session[:spree_user_signup]
    fire_event('spree.user.signup', :user => try_spree_current_user, :order => current_order(true))
  end

  session[:guest_token] = nil
  session[:spree_user_signup] = nil
end

#try_spree_current_userObject

proxy method to possible spree_current_user method Authentication extensions (such as spree_auth_devise) are meant to provide spree_current_user



34
35
36
# File 'lib/spree/core/controller_helpers.rb', line 34

def try_spree_current_user
  respond_to?(:spree_current_user) ? spree_current_user : nil
end