Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spree Guest email is saved

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.

like image 473
Aitizazk Avatar asked Dec 01 '15 16:12

Aitizazk


1 Answers

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.

like image 52
Cassio Cabral Avatar answered Jan 02 '23 21:01

Cassio Cabral