diff --git a/app/assets/stylesheets/mail/email.css.scss b/app/assets/stylesheets/mail/email.css.scss index 10a16941dd..a474a30da1 100644 --- a/app/assets/stylesheets/mail/email.css.scss +++ b/app/assets/stylesheets/mail/email.css.scss @@ -144,6 +144,10 @@ img.float-right { display: block; } +del.quantity_was { + color: #757575; +} + /* ------------------------------------- * HEADER *------------------------------------- */ diff --git a/app/jobs/standing_order_placement_job.rb b/app/jobs/standing_order_placement_job.rb index c415c7831f..9555e65581 100644 --- a/app/jobs/standing_order_placement_job.rb +++ b/app/jobs/standing_order_placement_job.rb @@ -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 diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb index a4b2db8b70..821bd1db3b 100644 --- a/app/mailers/spree/order_mailer_decorator.rb +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -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 diff --git a/app/views/spree/order_mailer/_order_summary.html.haml b/app/views/spree/order_mailer/_order_summary.html.haml index d1fbd96b36..9d18aa4880 100644 --- a/app/views/spree/order_mailer/_order_summary.html.haml +++ b/app/views/spree/order_mailer/_order_summary.html.haml @@ -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 diff --git a/app/views/spree/order_mailer/standing_order_placement_email.html.haml b/app/views/spree/order_mailer/standing_order_placement_email.html.haml new file mode 100644 index 0000000000..2734536991 --- /dev/null +++ b/app/views/spree/order_mailer/standing_order_placement_email.html.haml @@ -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' diff --git a/config/locales/en.yml b/config/locales/en.yml index 81abddfe4c..8f364e199e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 %{distributor} on your behalf." + email_placement_details_html: "Here are the details of your order for %{distributor}:" + 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:" diff --git a/spec/jobs/standing_order_placement_job_spec.rb b/spec/jobs/standing_order_placement_job_spec.rb index c6e6298541..b8636a1bc0 100644 --- a/spec/jobs/standing_order_placement_job_spec.rb +++ b/spec/jobs/standing_order_placement_job_spec.rb @@ -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