I have implemented phone verification in my Spree Application.
So the user have to verify phone number first before placing an order, but once the user places the order as guest, the next time his email is stored and it goes straight to /checkout/address
without going to /checkout/registration
first.
Where can I modify this code so that guest checkout always goes to /checkout/registration
first
Edit:
I checked the checkout_controller
and I think I can edit the functionality using checkout#edit
action.
But I am unable to find it in the gem files.
You could create a decorator for the checkout_controller
such as app/controllers/spree/checkout_controller_decorator.rb
and change this method to something like this below(code for the decorator file):
module Spree
CheckoutController.class_eval do
def before_address
# if the user has a default address, a callback takes care of setting
# that; but if he doesn't, we need to build an empty one here
if current_user.phone_number.present?
@order.bill_address ||= Address.build_default
@order.ship_address ||= Address.build_default if @order.checkout_steps.include?('delivery')
else
# some error telling that you need to fill the phone number
redirect_to registration_path
end
end
end
end
be aware that after the user is redirected you would have to deal with the redirecting back to the checkout page
You could change something on the User model also to ensure that the user has a phone number, it might conflict with the guest feature though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With