Spree Guest email is saved
Asked Answered
C

1

6

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.

Custom answered 1/12, 2015 at 16:44 Comment(1)
Add the Spree version please.Wallaby
W
4

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.

Wallaby answered 7/12, 2015 at 2:49 Comment(3)
i am getting "uninitialized constant Address" on the line " @order.bill_address ||= Address.build_default"Custom
I changed the answer, try now. The code is not complete is just a hunch or direction in how you could solve, you will find something to tweak here and there. The module is necessary, otherwise would be required to use Spree::Address alsoWallaby
Thanks alot that helped :)Custom

© 2022 - 2024 — McMap. All rights reserved.