diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c829d21625..9c265d1e56c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,7 +23,11 @@ def set_checkout_redirect referer_path = OpenFoodNetwork::RefererParser.path(request.referer) if referer_path is_checkout_path_the_referer = [main_app.checkout_path].include?(referer_path) - session["spree_user_return_to"] = is_checkout_path_the_referer ? referer_path : main_app.root_path + session["spree_user_return_to"] = if is_checkout_path_the_referer + referer_path + else + main_app.root_path + end end end @@ -86,12 +90,7 @@ def require_order_cycle end def check_hub_ready_for_checkout - # This condition is more rigourous than required by development to avoid coupling this - # condition to every controller spec - if current_distributor && current_order && - current_distributor.respond_to?(:ready_for_checkout?) && - !current_distributor.ready_for_checkout? - + if current_distributor_closed? current_order.empty! current_order.set_distribution! nil, nil flash[:info] = "The hub you have selected is temporarily closed for orders. Please try again later." @@ -99,6 +98,13 @@ def check_hub_ready_for_checkout end end + def current_distributor_closed? + current_distributor && + current_order && + current_distributor.respond_to?(:ready_for_checkout?) && + !current_distributor.ready_for_checkout? + end + def check_order_cycle_expiry if current_order_cycle.andand.closed? session[:expired_order_cycle_id] = current_order_cycle.id