Send a picked up email (rather than shipped email) when orders are picked up by customers

This commit is contained in:
binarygit
2022-09-19 14:35:36 +05:45
committed by Konrad
parent 22cf05ad94
commit 44db511e66
5 changed files with 24 additions and 10 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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!"

View File

@@ -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