From af79969d96a4c16a754df023f6d41c6ae753686b Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Sun, 4 Jul 2021 09:40:57 -0700 Subject: [PATCH] add SplitCheckoutController and conditional route --- app/constraints/split_checkout_constraint.rb | 9 +++++++++ app/controllers/split_checkout_controller.rb | 3 +++ config/routes.rb | 15 +++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/constraints/split_checkout_constraint.rb create mode 100644 app/controllers/split_checkout_controller.rb diff --git a/app/constraints/split_checkout_constraint.rb b/app/constraints/split_checkout_constraint.rb new file mode 100644 index 0000000000..e0b0a18eda --- /dev/null +++ b/app/constraints/split_checkout_constraint.rb @@ -0,0 +1,9 @@ +class SplitCheckoutConstraint + def matches?(request) + Flipper.enabled? :split_checkout, current_user(request) + end + + def current_user(request) + @spree_current_user ||= request.env['warden'].user + end +end diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb new file mode 100644 index 0000000000..4067ad5060 --- /dev/null +++ b/app/controllers/split_checkout_controller.rb @@ -0,0 +1,3 @@ +class SplitCheckoutController < CheckoutController + +end diff --git a/config/routes.rb b/config/routes.rb index 3385d97a02..1e44f533d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,10 +69,17 @@ Openfoodnetwork::Application.routes.draw do resources :webhooks, only: [:create] end - get '/checkout', to: 'checkout#edit' , as: :checkout - put '/checkout', to: 'checkout#update' , as: :update_checkout - get '/checkout/:state', to: 'checkout#edit', as: :checkout_state - get '/checkout/paypal_payment/:order_id', to: 'checkout#paypal_payment', as: :paypal_payment + constraints(SplitCheckoutConstraint.new) do + get '/checkout', to: 'split_checkout#edit', as: :checkout + put '/checkout', to: 'split_checkout#update', as: :update_checkout + get '/checkout/:state', to: 'split_checkout#edit', as: :checkout_state + get '/checkout/paypal_payment/:order_id', to: 'split_checkout#paypal_payment', as: :paypal_payment + end + + get '/checkout', to: 'checkout#edit' + put '/checkout', to: 'checkout#update' + get '/checkout/:state', to: 'checkout#edit' + get '/checkout/paypal_payment/:order_id', to: 'checkout#paypal_payment' get 'embedded_shopfront/shopfront_session', to: 'application#shopfront_session' post 'embedded_shopfront/enable', to: 'application#enable_embedded_styles'