diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb index 180d138237..63fff5a525 100644 --- a/app/controllers/concerns/white_label.rb +++ b/app/controllers/concerns/white_label.rb @@ -10,5 +10,12 @@ module WhiteLabel # if the distributor has the hide_ofn_navigation preference set to true # then we should hide the OFN navigation @hide_ofn_navigation = distributor.hide_ofn_navigation + + # if the distributor has the hide_ofn_navigation preference + # set to false, there is no need to check the white_label_logo preference + return unless @hide_ofn_navigation + + @white_label_logo = distributor.white_label_logo + @white_label_distributor = distributor end end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index c34da439a0..6443b19bab 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -16,7 +16,8 @@ class Enterprise < ApplicationRecord large: { resize_to_fill: [1200, 260] }, }.freeze WHITE_LABEL_LOGO_SIZES = { - default: { gravity: "Center", resize: "217x44^", crop: '217x44+0+0' } + default: { gravity: "Center", resize: "217x44^", crop: '217x44+0+0' }, + mobile: { gravity: "Center", resize: "75x26^", crop: '75x26+0+0' }, }.freeze VALID_INSTAGRAM_REGEX = %r{\A[a-zA-Z0-9._]{1,30}([^/-]*)\z} diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index ec64ecdcf5..cfb7aa0640 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -3,7 +3,10 @@ %ul.nav-logo %li.ofn-logo %a{href: main_app.root_path} - %img{src: ContentConfig.url_for(:logo)} + - if @white_label_logo&.variable? + = image_tag @white_label_distributor.white_label_logo_url(:default) + - else + %img{src: ContentConfig.url_for(:logo)} %li.powered-by %img{src: '/favicon.ico'} %span diff --git a/app/views/shared/menu/_mobile_menu.html.haml b/app/views/shared/menu/_mobile_menu.html.haml index aca1fa70d6..75540b5ed9 100644 --- a/app/views/shared/menu/_mobile_menu.html.haml +++ b/app/views/shared/menu/_mobile_menu.html.haml @@ -6,7 +6,10 @@ %section.left .ofn-logo %a{href: main_app.root_path} - %img{src: ContentConfig.url_for(:logo_mobile), srcset: ContentConfig.url_for(:logo_mobile_svg), width: "75", height: "26"} + - if @white_label_logo&.variable? + = image_tag @white_label_distributor.white_label_logo_url(:mobile) + - else + %img{src: ContentConfig.url_for(:logo_mobile), srcset: ContentConfig.url_for(:logo_mobile_svg), width: "75", height: "26"} %section.right{"ng-cloak" => true} %span.cart-span{"ng-class" => "{ dirty: Cart.dirty || Cart.empty(), 'pure-dirty': Cart.dirty }"} diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 24e930725d..5aa11d7998 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -5,6 +5,7 @@ require 'system_helper' describe 'White label setting' do include AuthenticationHelper include ShopWorkflow + include FileHelper let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } let!(:shipping_method) { create(:shipping_method, distributors: [distributor]) } @@ -18,6 +19,13 @@ describe 'White label setting' do variants: [product.variants.first]) } let!(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) } + let(:complete_order) { + create(:order_with_credit_payment, + user: nil, + email: "guest@user.com", + distributor: distributor, + order_cycle: order_cycle) + } let(:ofn_navigation) { 'ul.nav-main-menu' } @@ -102,13 +110,6 @@ describe 'White label setting' do end context "when the user has a complete order" do - let(:complete_order) { - create(:order_with_credit_payment, - user: nil, - email: "guest@user.com", - distributor: distributor, - order_cycle: order_cycle) - } before do set_order(complete_order) end @@ -162,6 +163,112 @@ describe 'White label setting' do it_behaves_like "does not hide the OFN navigation" end end + + context "manage the white_label_logo preference" do + context "when the distributor has no logo" do + before do + distributor.update_attribute(:hide_ofn_navigation, true) + end + + shared_examples "shows/hide the right logos" do + it "shows the OFN logo on shop page" do + expect(page).to have_selector "img[src*='/default_images/ofn-logo.png']" + end + end + + context "on shop page" do + before do + visit main_app.enterprise_shop_path(distributor) + end + + it_behaves_like "shows/hide the right logos" + end + + context "on cart page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit main_app.cart_path + end + + it_behaves_like "shows/hide the right logos" + end + + context "on checkout page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit checkout_path + end + + it_behaves_like "shows/hide the right logos" + end + + context "on order confirmation page" do + before do + visit order_path(complete_order, order_token: complete_order.token) + end + + it_behaves_like "shows/hide the right logos" + end + end + + context "when the distributor has a logo" do + before do + distributor.update_attribute(:hide_ofn_navigation, true) + distributor.update white_label_logo: white_logo_file + end + + shared_examples "shows/hide the right logos" do + it "shows the white label logo on shop page" do + expect(page).to have_selector "img[src*='/logo-white.png']" + end + it "does not show the OFN logo on shop page" do + expect(page).not_to have_selector "img[src*='/default_images/ofn-logo.png']" + end + end + + context "on shop page" do + before do + visit main_app.enterprise_shop_path(distributor) + end + + it_behaves_like "shows/hide the right logos" + end + + context "on cart page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit main_app.cart_path + end + + it_behaves_like "shows/hide the right logos" + end + + context "on checkout page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit checkout_path + end + + it_behaves_like "shows/hide the right logos" + end + + context "on order confirmation page" do + before do + visit order_path(complete_order, order_token: complete_order.token) + end + + it_behaves_like "shows/hide the right logos" + end + end + end end context "when the white label feature is deactivated" do