Permalink
Browse files

Add proxy method current_user internal to Spree for access to spree_c…

…urrent_user
  • Loading branch information...
1 parent 22b9309 commit e9e6aa20aa440d4d002c82267e16611d861bde42 @radar radar committed Jun 1, 2012
Showing with 14 additions and 8 deletions.
  1. +11 −5 core/app/controllers/spree/base_controller.rb
  2. +3 −3 core/app/controllers/spree/checkout_controller.rb
@@ -39,11 +39,17 @@ def title
end
end
+ # proxy method to *possible* spree_current_user method
+ # Authentication extensions (such as spree_auth_devise) are meant to provide spree_current_user
+ def current_user
+ respond_to?(:spree_current_user) ? spree_current_user : nil
+ end
+
protected
def set_current_order
- if spree_current_user
- last_incomplete_order = spree_current_user.last_incomplete_spree_order
+ if current_user
+ last_incomplete_order = current_user.last_incomplete_spree_order
if session[:order_id].nil? && last_incomplete_order
session[:order_id] = last_incomplete_order.id
elsif current_order && last_incomplete_order && current_order != last_incomplete_order
@@ -54,7 +60,7 @@ def set_current_order
# Needs to be overriden so that we use Spree's Ability rather than anyone else's.
def current_ability
- @current_ability ||= Spree::Ability.new(spree_current_user)
+ @current_ability ||= Spree::Ability.new(current_user)
end
def store_location
@@ -79,7 +85,7 @@ def store_location
def unauthorized
respond_to do |format|
format.html do
- if spree_current_user
+ if current_user
flash.now[:error] = t(:authorization_failure)
render 'spree/shared/unauthorized', :layout => '/spree/layouts/spree_application', :status => 401
else
@@ -122,7 +128,7 @@ def fire_event(name, extra_payload = {})
# add additional keys as appropriate. Override this method if you need additional data when
# responding to a notification
def default_notification_payload
- {:user => spree_current_user, :order => current_order}
+ {:user => current_user, :order => current_order}
end
private
@@ -47,17 +47,17 @@ def load_order
end
def associate_user
- if spree_current_user && @order
+ if current_user && @order
if @order.user.blank? || @order.email.blank?
- @order.associate_user!(spree_current_user)
+ @order.associate_user!(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 => spree_current_user, :order => current_order(true))
+ fire_event('spree.user.signup', :user => current_user, :order => current_order(true))
end
session[:guest_token] = nil

0 comments on commit e9e6aa2

Please sign in to comment.