From 3ed89fc2dbaff49f2cd31ae2e97bb1fa48180d94 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 25 Apr 2023 10:27:57 +0200 Subject: [PATCH 1/4] Create a subscription confirmation email preview of the last completed order Available on: `/rails/mailers/subscription_mailer/confirmation_email` --- spec/mailers/previews/subscription_mailer_preview.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spec/mailers/previews/subscription_mailer_preview.rb diff --git a/spec/mailers/previews/subscription_mailer_preview.rb b/spec/mailers/previews/subscription_mailer_preview.rb new file mode 100644 index 0000000000..91e11b5a1e --- /dev/null +++ b/spec/mailers/previews/subscription_mailer_preview.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class SubscriptionMailerPreview < ActionMailer::Preview + def confirmation_email + SubscriptionMailer.confirmation_email(Spree::Order.complete.last) + end +end From f7d06fe0e8711ccc0d6a753e20db587a6c08cc11 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 25 Apr 2023 10:29:08 +0200 Subject: [PATCH 2/4] Do not display OFN banner on subscription confirmation email if white label + add specs that test for the presence of the footer logo which is in the header (I know it's a bit contradictory) --- app/mailers/subscription_mailer.rb | 1 + app/views/layouts/mailer.html.haml | 27 ++++++++++++------------ spec/mailers/subscription_mailer_spec.rb | 14 ++++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index 174fef790b..51000576c1 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -11,6 +11,7 @@ class SubscriptionMailer < ApplicationMailer def confirmation_email(order) @type = 'confirmation' @order = order + @hide_ofn_navigation = @order.distributor.hide_ofn_navigation send_mail(order) end diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml index 0160dfd727..f559f67d62 100644 --- a/app/views/layouts/mailer.html.haml +++ b/app/views/layouts/mailer.html.haml @@ -7,19 +7,20 @@ = Spree::Config[:site_name] = stylesheet_pack_tag 'mail' %body{:bgcolor => "#FFFFFF" } - %table.head-wrap{:bgcolor => "#f2f2f2"} - %tr - %td - %td.header.container - .content - %table{:bgcolor => "#f2f2f2"} - %tr - %td - %img{src: ContentConfig.url_for(:footer_logo), width: "144", height: "50"}/ - %td{:align => "right"} - %h6.collapse - = Spree::Config[:site_name] - %td + - unless @hide_ofn_navigation + %table.head-wrap{:bgcolor => "#f2f2f2"} + %tr + %td + %td.header.container + .content + %table{:bgcolor => "#f2f2f2"} + %tr + %td + %img{src: ContentConfig.url_for(:footer_logo), width: "144", height: "50"}/ + %td{:align => "right"} + %h6.collapse + = Spree::Config[:site_name] + %td %table.body-wrap %tr diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb index 0c4a85c6d9..5ce3ad3720 100644 --- a/spec/mailers/subscription_mailer_spec.rb +++ b/spec/mailers/subscription_mailer_spec.rb @@ -117,6 +117,10 @@ describe SubscriptionMailer, type: :mailer do expect(body).to include "This order was automatically placed for you" end + it "display the OFN header by default" do + expect(email.body).to include(ContentConfig.url_for(:footer_logo)) + end + describe "linking to order page" do let(:order_link_href) { "href=\"#{order_url(order)}\"" } @@ -152,6 +156,16 @@ describe SubscriptionMailer, type: :mailer do expect(email.body).to include('NOT PAID') end end + + context 'when hide OFN navigation is enabled for the distributor of the order' do + before do + allow(order.distributor).to receive(:hide_ofn_navigation).and_return(true) + end + + it 'does not display the OFN navigation' do + expect(email.body).to_not include(ContentConfig.url_for(:footer_logo)) + end + end end describe "empty order notification" do From dfafbfe996d54d49b0429b96158b83db84fcfeae Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 17 May 2023 11:28:16 +0200 Subject: [PATCH 3/4] Create an order confirmation email preview of the last completed order Available on `/rails/mailers/order_mailer/confirm_email_for_customer` --- spec/mailers/previews/order_mailer_preview.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spec/mailers/previews/order_mailer_preview.rb diff --git a/spec/mailers/previews/order_mailer_preview.rb b/spec/mailers/previews/order_mailer_preview.rb new file mode 100644 index 0000000000..13bdb4f711 --- /dev/null +++ b/spec/mailers/previews/order_mailer_preview.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class OrderMailerPreview < ActionMailer::Preview + def confirm_email_for_customer + Spree::OrderMailer.confirm_email_for_customer(Spree::Order.complete.last) + end +end From 2336981ca09d7893fca8ac87822f5c24123e90ac Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 17 May 2023 11:28:33 +0200 Subject: [PATCH 4/4] Do not display OFN banner on order confirmation email if white label --- app/mailers/spree/order_mailer.rb | 1 + spec/mailers/order_mailer_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb index 57f8766098..a2fda5d94f 100644 --- a/app/mailers/spree/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -28,6 +28,7 @@ module Spree def confirm_email_for_customer(order_or_order_id, resend = false) @order = find_order(order_or_order_id) + @hide_ofn_navigation = @order.distributor.hide_ofn_navigation I18n.with_locale valid_locale(@order.user) do subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend) mail(to: @order.email, diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index 5a20e0fd2e..af305532a2 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -44,6 +44,20 @@ describe Spree::OrderMailer do described_class.confirm_email_for_customer(order.id).deliver_now }.to_not raise_error end + + it "display the OFN header by default" do + expect(email.body).to include(ContentConfig.url_for(:footer_logo)) + end + + context 'when hide OFN navigation is enabled for the distributor of the order' do + before do + allow(order.distributor).to receive(:hide_ofn_navigation).and_return(true) + end + + it 'does not display the OFN navigation' do + expect(email.body).to_not include(ContentConfig.url_for(:footer_logo)) + end + end end describe '#confirm_email_for_shop' do