diff --git a/app/mailers/spree/shipment_mailer.rb b/app/mailers/spree/shipment_mailer.rb index f15fe7fade..ca77cbd047 100644 --- a/app/mailers/spree/shipment_mailer.rb +++ b/app/mailers/spree/shipment_mailer.rb @@ -2,9 +2,10 @@ module Spree class ShipmentMailer < BaseMailer - def shipped_email(shipment, resend = false) + def shipped_email(shipment, delivery:) @shipment = shipment.respond_to?(:id) ? shipment : Spree::Shipment.find(shipment) - subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '') + base_subject + @delivery = delivery + subject = base_subject mail(to: @shipment.order.email, from: from_address, subject: subject) end diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 8ab08a51ac..cd8cc0142d 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -343,7 +343,8 @@ module Spree end def send_shipped_email - ShipmentMailer.shipped_email(id).deliver_later + delivery = !!shipping_method.require_ship_address + ShipmentMailer.shipped_email(id, delivery: delivery).deliver_later end def update_adjustments diff --git a/app/views/spree/shipment_mailer/shipped_email.html.haml b/app/views/spree/shipment_mailer/shipped_email.html.haml index 0796d62b81..da606c35a0 100644 --- a/app/views/spree/shipment_mailer/shipped_email.html.haml +++ b/app/views/spree/shipment_mailer/shipped_email.html.haml @@ -1,7 +1,12 @@ %h3 = t('.dear_customer') -%p.lead - = t('.instructions', distributor: @shipment.order.distributor.name) + +- if @delivery + %p.lead + = t('.instructions', distributor: @shipment.order.distributor.name) +- else + %p.lead + = t('.picked_up_instructions', distributor: @shipment.order.distributor.name) %p %strong diff --git a/config/locales/en.yml b/config/locales/en.yml index 4ab0928132..6c3820abb8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4221,6 +4221,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using thanks: "Thank you for your business." track_information: ! "Tracking Information: %{tracking}" track_link: ! "Tracking Link: %{url}" + picked_up_instructions: "Your order from %{distributor} has been picked-up" test_mailer: test_email: greeting: "Congratulations!" diff --git a/spec/mailers/shipment_mailer_spec.rb b/spec/mailers/shipment_mailer_spec.rb index 132c1267b1..06bed6dbb3 100644 --- a/spec/mailers/shipment_mailer_spec.rb +++ b/spec/mailers/shipment_mailer_spec.rb @@ -17,31 +17,37 @@ describe Spree::ShipmentMailer do context ":from not set explicitly" do it "falls back to spree config" do - message = Spree::ShipmentMailer.shipped_email(shipment) + message = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) expect(message.from).to eq [Spree::Config[:mails_from]] end end # Regression test for #2196 it "doesn't include out of stock in the email body" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment) + shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) expect(shipment_email.body).to_not include(%{Out of Stock}) end it "shipment_email accepts an shipment id as an alternative to an Shipment object" do expect(Spree::Shipment).to receive(:find).with(shipment.id).and_return(shipment) expect { - Spree::ShipmentMailer.shipped_email(shipment.id).deliver_now + Spree::ShipmentMailer.shipped_email(shipment.id, delivery: true).deliver_now }.to_not raise_error end it "includes the distributor's name in the subject" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment) + shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) expect(shipment_email.subject).to include("#{distributor.name} Shipment Notification") end it "includes the distributor's name in the body" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment) + shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) expect(shipment_email.body).to include("Your order from #{distributor.name} has been shipped") end + + it "picked_up email includes different text in body" do + text = "Your order from #{distributor.name} has been picked-up" + picked_up_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: false) + expect(picked_up_email.body).to include(text) + end end