diff --git a/app/views/subscription_mailer/placement_email.html.haml b/app/views/subscription_mailer/placement_email.html.haml
index 3a12a296e9..31f13b6513 100644
--- a/app/views/subscription_mailer/placement_email.html.haml
+++ b/app/views/subscription_mailer/placement_email.html.haml
@@ -3,11 +3,18 @@
%p.callout
= t("email_so_placement_explainer_html")
- - allow_changes = !!@order.distributor.allow_order_changes?
- = t("email_so_edit_#{allow_changes}_html",
- orders_close_at: l(@order.order_cycle.orders_close_at, format: mail_long_datetime_format),
- order_url: spree.order_url(@order))
- = t("email_so_contact_distributor_html", distributor: @order.distributor.name, email: @order.distributor.contact.email)
+
+ - if @order.user.present?
+ - allow_changes = !!@order.distributor.allow_order_changes?
+ = t("email_so_edit_#{allow_changes}_html",
+ orders_close_at: l(@order.order_cycle.orders_close_at, format: mail_long_datetime_format),
+ order_url: spree.order_url(@order))
+ = t("email_so_contact_distributor_html", distributor: @order.distributor.name, email: @order.distributor.contact.email)
+ - else
+ = t("email_so_contact_distributor_to_change_order_html",
+ orders_close_at: l(@order.order_cycle.orders_close_at, format: mail_long_datetime_format),
+ distributor: @order.distributor.name,
+ email: @order.distributor.contact.email)
%p
%h4
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 14eb3ebaf7..2efdb4d0e0 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1461,6 +1461,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
email_so_edit_true_html: "You can make changes until orders close on %{orders_close_at}."
email_so_edit_false_html: "You can view details of this order at any time."
email_so_contact_distributor_html: "If you have any questions you can contact %{distributor} via %{email}."
+ email_so_contact_distributor_to_change_order_html: "This order was automatically created for you. You can make changes until orders close on %{orders_close_at} by contacting %{distributor} via %{email}."
email_so_confirmation_intro_html: "Your order with %{distributor} is now confirmed"
email_so_confirmation_explainer_html: "This order was automatically placed for you, and it has now been finalised."
email_so_confirmation_details_html: "Here's everything you need to know about your order from %{distributor}:"
diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb
index 662317ad6e..7e8ce249d4 100644
--- a/spec/mailers/subscription_mailer_spec.rb
+++ b/spec/mailers/subscription_mailer_spec.rb
@@ -56,19 +56,37 @@ describe SubscriptionMailer do
SubscriptionMailer.placement_email(order, {}).deliver
end
- let(:customer) { create(:customer, enterprise: shop) }
+ context "when the customer has a user account" do
+ let(:customer) { create(:customer, enterprise: shop) }
- it "provides link to make changes" do
- expect(body).to match /make changes<\/a>/
- expect(body).to_not match /view details of this order<\/a>/
+ it "provides link to make changes" do
+ expect(body).to match /make changes<\/a>/
+ expect(body).to_not match /view details of this order<\/a>/
+ end
+
+ context "when the distributor does not allow changes to the order" do
+ let(:shop) { create(:enterprise, allow_order_changes: false) }
+
+ it "provides link to view details" do
+ expect(body).to_not match /make changes<\/a>/
+ expect(body).to match /view details of this order<\/a>/
+ end
+ end
end
- context "when the distributor does not allow changes to the order" do
- let(:shop) { create(:enterprise, allow_order_changes: false) }
+ context "when the customer has no user account" do
+ let(:customer) { create(:customer, enterprise: shop, user: nil) }
- it "provides link to view details" do
- expect(body).to_not match /make changes<\/a>/
- expect(body).to match /view details of this order<\/a>/
+ it "does not provide link" do
+ expect(body).to_not match /#{order_link_href}/
+ end
+
+ context "when the distributor does not allow changes to the order" do
+ let(:shop) { create(:enterprise, allow_order_changes: false) }
+
+ it "does not provide link" do
+ expect(body).to_not match /#{order_link_href}/
+ end
end
end
end