Ait*_*azk 6 gem rubygems e-commerce spree ruby-on-rails-4
我在我的狂欢应用程序中实现了电话验证.
因此,用户必须在下订单之前首先验证电话号码,但是一旦用户将订单作为客人下订单,下次他的电子邮件被存储时它就会直接进入/checkout/address而不会/checkout/registration先到达.
我在哪里可以修改此代码,以便访客结帐总是/checkout/registration先到
编辑:
我查了一下checkout_controller,我想我可以使用checkout#edit动作编辑功能.
但是我无法在gem文件中找到它.
checkout_controller您可以为诸如此类创建一个装饰器app/controllers/spree/checkout_controller_decorator.rb,并将此方法更改为如下所示(装饰器文件的代码):
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
Run Code Online (Sandbox Code Playgroud)
请注意,用户重定向后,您必须处理重定向回结账页面的问题
您还可以更改用户模型上的某些内容,以确保用户拥有电话号码,但这可能与访客功能发生冲突。