module Spree::CheckoutControllerDecorator
Public Class Methods
prepended(base)
click to toggle source
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 5 def self.prepended(base) base.before_action :check_registration, except: [:registration, :update_registration] base.before_action :check_authorization # This action builds some associations on the order, ex. addresses, which we # don't to build or save here. base.skip_before_action :setup_for_current_state, only: [:registration, :update_registration] end
Public Instance Methods
registration()
click to toggle source
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 14 def registration @user = Spree::User.new end
update_registration()
click to toggle source
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 18 def update_registration if params[:order][:email] =~ Devise.email_regexp && current_order.update(email: params[:order][:email]) redirect_to spree.checkout_path else flash[:registration_error] = t(:email_is_invalid, scope: [:errors, :messages]) @user = Spree::User.new render 'registration' end end
Private Instance Methods
already_registered?()
click to toggle source
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 57 def already_registered? spree_current_user || guest_authenticated? end
check_registration()
click to toggle source
Introduces a registration step whenever the registration_step
preference is true.
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 45 def check_registration return unless registration_required? store_location redirect_to spree.checkout_registration_path end
completion_route()
click to toggle source
Overrides the equivalent method defined in Spree::Core. This variation of the method will ensure that users are redirected to the tokenized order url unless authenticated as a registered user.
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 68 def completion_route return spree.order_path(@order) if spree_current_user spree.token_order_path(@order, @order.guest_token) end
guest_authenticated?()
click to toggle source
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 61 def guest_authenticated? current_order&.email.present? && Spree::Config[:allow_guest_checkout] end
order_params()
click to toggle source
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 30 def order_params params. fetch(:order, {}). permit(:email) end
registration_required?()
click to toggle source
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 52 def registration_required? Spree::Auth::Config[:registration_step] && !already_registered? end
skip_state_validation?()
click to toggle source
# File lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb, line 36 def skip_state_validation? %w(registration update_registration).include?(params[:action]) end