mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Send a picked up email (rather than shipped email) when orders are picked up by customers
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user