diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb index 5b9d23b96b..575fa68d25 100644 --- a/app/controllers/concerns/white_label.rb +++ b/app/controllers/concerns/white_label.rb @@ -4,21 +4,11 @@ module WhiteLabel extend ActiveSupport::Concern include EnterprisesHelper - def hide_ofn_navigation + def hide_ofn_navigation(distributor = current_distributor) return false unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label) # if the distributor has the hide_ofn_navigation preference set to true # then we should hide the OFN navigation @hide_ofn_navigation = distributor.preferred_hide_ofn_navigation end - - private - - def distributor - return current_distributor unless request.path.start_with?("/orders/") - - # if we are on an order confirmation page, - # we need to get the distributor from the order, not the current one - Spree::Order.find_by(number: params[:id]).distributor - end end diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index 07d8fbb895..e0a8d2281b 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -15,7 +15,8 @@ module Spree respond_to :html, :json before_action :check_authorization - before_action :set_current_order, only: :update + before_action :set_order_from_params, only: :show + before_action :set_current_order, only: [:edit, :update] before_action :filter_order_params, only: :update prepend_before_action :require_order_authentication, only: :show @@ -23,12 +24,13 @@ module Spree prepend_before_action :require_distributor_chosen, only: :edit before_action :check_hub_ready_for_checkout, only: :edit before_action :check_at_least_one_line_item, only: :update - before_action :hide_ofn_navigation, only: [:show, :edit] - def show - @order = Spree::Order.find_by!(number: params[:id]) + before_action only: [:show, :edit] do + hide_ofn_navigation(@order.distributor) end + def show; end + def empty if @order = current_order @order.empty! @@ -39,7 +41,6 @@ module Spree # Patching to redirect to shop if order is empty def edit - @order = current_order(true) @insufficient_stock_lines = @order.insufficient_stock_lines @unavailable_order_variants = OrderCycleDistributedVariants. new(current_order_cycle, current_distributor).unavailable_order_variants(@order) @@ -108,6 +109,10 @@ module Spree private + def set_order_from_params + @order = Spree::Order.find_by!(number: params[:id]) + end + def set_current_order @order = current_order(true) end