mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Sending placement email when standing order order in placed on OC open
This commit is contained in:
@@ -144,6 +144,10 @@ img.float-right {
|
||||
display: block;
|
||||
}
|
||||
|
||||
del.quantity_was {
|
||||
color: #757575;
|
||||
}
|
||||
|
||||
/* -------------------------------------
|
||||
* HEADER
|
||||
*------------------------------------- */
|
||||
|
||||
@@ -46,6 +46,6 @@ class StandingOrderPlacementJob
|
||||
end
|
||||
|
||||
def send_placement_email(order, changes)
|
||||
# Nothing yet
|
||||
Spree::OrderMailer.standing_order_placement_email(order, changes).deliver
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,6 +39,16 @@ Spree::OrderMailer.class_eval do
|
||||
:reply_to => @order.distributor.contact.email)
|
||||
end
|
||||
|
||||
def standing_order_placement_email(order, changes)
|
||||
@changes = changes
|
||||
find_order(order) # Finds an order instance from an id
|
||||
subject = "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}"
|
||||
mail(:to => @order.email,
|
||||
:from => from_address,
|
||||
:subject => subject,
|
||||
:reply_to => @order.distributor.email)
|
||||
end
|
||||
|
||||
def find_order(order)
|
||||
@order = order.respond_to?(:id) ? order : Spree::Order.find(order)
|
||||
end
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
%small
|
||||
%em= raw(item.variant.product.supplier.name)
|
||||
%td{:align => "right"}
|
||||
- if @changes && @changes[item.id].present?
|
||||
%del.quantity_was= @changes[item.id]
|
||||
= item.quantity
|
||||
-# Report changes made to standing orders
|
||||
|
||||
%td{:align => "right"}
|
||||
= item.display_amount_with_adjustments
|
||||
%tfoot
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
%table.social.white-bg{:width => "100%"}
|
||||
%tr
|
||||
%td
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
%td
|
||||
%h3
|
||||
= t :email_confirm_customer_greeting, name: @order.bill_address.firstname
|
||||
%h4
|
||||
= t :email_placement_intro_html, distributor: @order.distributor.name
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
%td{:align => "right"}
|
||||
%img.float-right{:src => "#{@order.distributor.logo.url(:medium)}"}/
|
||||
%span.clear
|
||||
|
||||
%p
|
||||
%h4
|
||||
= t :email_confirm_customer_number_html, number: @order.number
|
||||
%p
|
||||
= t :email_placement_details_html, distributor: @order.distributor.name
|
||||
|
||||
- if @changes.any?
|
||||
%p.callout
|
||||
= t :email_placement_changes
|
||||
= render 'order_summary'
|
||||
= render 'payment'
|
||||
= render 'shipping'
|
||||
= render 'special_instructions'
|
||||
= render 'signoff'
|
||||
@@ -1149,6 +1149,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
email_payment_not_paid: NOT PAID
|
||||
email_payment_summary: Payment summary
|
||||
email_payment_method: "Paying via:"
|
||||
email_placement_intro_html: "This email is to notify you that an order has been automatically placed with <strong>%{distributor}</strong> on your behalf."
|
||||
email_placement_details_html: "Here are the details of your order for <strong>%{distributor}</strong>:"
|
||||
email_placement_changes: "Unfortunately, not all products that you requested were available. The original quantities that you requested appear crossed-out below."
|
||||
email_shipping_delivery_details: Delivery details
|
||||
email_shipping_delivery_time: "Delivery on:"
|
||||
email_shipping_delivery_address: "Delivery address:"
|
||||
|
||||
@@ -55,27 +55,30 @@ describe StandingOrderPlacementJob do
|
||||
end
|
||||
|
||||
describe "processing a standing order order" do
|
||||
let(:changes) { double(:changes) }
|
||||
let(:changes) { {} }
|
||||
|
||||
before do
|
||||
form = StandingOrderForm.new(standing_order1)
|
||||
form.send(:initialise_orders!)
|
||||
expect_any_instance_of(Spree::Payment).to_not receive(:process!)
|
||||
allow(job).to receive(:cap_quantity_and_store_changes) { changes }
|
||||
allow(job).to receive(:send_placement_email)
|
||||
allow(job).to receive(:send_placement_email).and_call_original
|
||||
end
|
||||
|
||||
it "moves orders to completion, but does not process the payment" do
|
||||
order = standing_order1.orders.first
|
||||
ActionMailer::Base.deliveries.clear
|
||||
expect{job.send(:process, order)}.to change{order.reload.completed_at}.from(nil)
|
||||
expect(order.completed_at).to be_within(5.seconds).of Time.now
|
||||
expect(order.payments.first.state).to eq "checkout"
|
||||
end
|
||||
|
||||
it "calls #send_placement_email with the order and any changes made" do
|
||||
it "sends only a placement email, no confirmation emails" do
|
||||
order = standing_order1.orders.first
|
||||
job.send(:process, order)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
expect{job.send(:process, order)}.to_not enqueue_job ConfirmOrderJob
|
||||
expect(job).to have_received(:send_placement_email).with(order, changes).once
|
||||
expect(ActionMailer::Base.deliveries.count).to be 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user