diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 48d5cf060a..2c8b7f7cfe 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -5,6 +5,7 @@ require 'open_food_network/address_finder' class CheckoutController < ::BaseController include OrderStockCheck include OrderCompletion + include WhiteLabel layout 'darkswarm' @@ -27,6 +28,8 @@ class CheckoutController < ::BaseController before_action :associate_user before_action :check_authorization + before_action :hide_ofn_navigation, only: :edit + helper 'spree/orders' def edit; end diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb new file mode 100644 index 0000000000..19c54741f8 --- /dev/null +++ b/app/controllers/concerns/white_label.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module WhiteLabel + extend ActiveSupport::Concern + include EnterprisesHelper + + def hide_ofn_navigation + # 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/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 2fc7f43b44..058c6528ed 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -7,6 +7,7 @@ class EnterprisesController < BaseController helper Spree::ProductsHelper include OrderCyclesHelper include SerializerHelper + include WhiteLabel protect_from_forgery except: :check_permalink @@ -14,6 +15,7 @@ class EnterprisesController < BaseController prepend_before_action :set_order_cycles, :require_distributor_chosen, :reset_order, only: :shop before_action :clean_permalink, only: :check_permalink + before_action :hide_ofn_navigation, only: :shop respond_to :js, only: :permalink_checker diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index e33bd0038b..c1a63c2c44 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -10,6 +10,7 @@ class SplitCheckoutController < ::BaseController include CheckoutCallbacks include OrderCompletion include CablecarResponses + include WhiteLabel helper 'terms_and_conditions' helper 'checkout' @@ -18,6 +19,7 @@ class SplitCheckoutController < ::BaseController helper OrderHelper before_action :set_checkout_redirect + before_action :hide_ofn_navigation, only: [:edit, :update] def edit redirect_to_step_based_on_order unless params[:step] diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index 95e9390f9b..07d8fbb895 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -5,6 +5,7 @@ module Spree include OrderCyclesHelper include Rails.application.routes.url_helpers include CablecarResponses + include WhiteLabel layout 'darkswarm' @@ -22,6 +23,7 @@ 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]) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 38c0aff325..2f60c848b4 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -87,26 +87,4 @@ module EnterprisesHelper main_app.producers_url end end - - def hide_ofn_navigation? - # if we are not on a shopfront, a cart page, checkout page or the order confirmation page - # then we should show the OFN navigation - # whatever the current distributor has set for the hide_ofn_navigation preference - return false unless current_distributor && current_page?(main_app.enterprise_shop_path(current_distributor)) || # shopfront - request.path.start_with?(main_app.checkout_path) || # checkout - current_page?(main_app.cart_path) || # cart - request.path.start_with?("/orders/") # order confirmation - - distributor = if 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 - else - current_distributor - end - - # if the current distributor has the hide_ofn_navigation preference set to true - # then we should hide the OFN navigation - distributor.preferred_hide_ofn_navigation - end end diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index f9c36f4803..ec64ecdcf5 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -10,7 +10,7 @@ = t 'powered_by' %a{href: '/'} = t 'title' - - unless hide_ofn_navigation? + - unless @hide_ofn_navigation %ul.nav-main-menu - [*1..7].each do |menu_number| - menu_name = "menu_#{menu_number}" diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index c6ce2a43e6..41da37c00f 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -91,6 +91,7 @@ describe Spree::OrdersController, type: :controller do it "redirects to shop when order is empty" do allow(controller).to receive(:current_distributor).and_return(distributor) + allow(distributor).to receive(:preferred_hide_ofn_navigation).and_return false allow(controller).to receive(:current_order_cycle).and_return(order_cycle) allow(controller).to receive(:current_order).and_return order allow(order).to receive_message_chain(:line_items, :empty?).and_return true