From 4bd1ff20111237f1a103b4098f7d95faca5c1885 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 2 Apr 2015 16:00:48 +1100 Subject: [PATCH] Extract the bulk of the confirmation emails into partials, eliminating a lot of duplication --- .../order_mailer/_order_summary.html.haml | 46 ++++++ .../spree/order_mailer/_payment.html.haml | 14 ++ .../spree/order_mailer/_shipping.html.haml | 59 ++++++++ .../_special_instructions.html.haml | 7 + .../confirm_email_for_customer.html.haml | 133 +----------------- .../confirm_email_for_shop.html.haml | 132 +---------------- 6 files changed, 134 insertions(+), 257 deletions(-) create mode 100644 app/views/spree/order_mailer/_order_summary.html.haml create mode 100644 app/views/spree/order_mailer/_payment.html.haml create mode 100644 app/views/spree/order_mailer/_shipping.html.haml create mode 100644 app/views/spree/order_mailer/_special_instructions.html.haml diff --git a/app/views/spree/order_mailer/_order_summary.html.haml b/app/views/spree/order_mailer/_order_summary.html.haml new file mode 100644 index 0000000000..0e68c38c9b --- /dev/null +++ b/app/views/spree/order_mailer/_order_summary.html.haml @@ -0,0 +1,46 @@ +%table.order-summary{:width => "100%"} + %thead + %tr + %th{:align => "left"} + %h4 Item + %th{:align => "right", :width => "25%"} + %h4 Qty + %th{:align => "right", :width => "25%"} + %h4 Price + %tbody + - @order.line_items.each do |item| + %tr + %td + - if item.variant.product.name == item.variant.name_to_display + %strong= "#{raw(item.variant.product.name)}" + - else + %strong + %span= "#{raw(item.variant.product.name)}" + %span= "- " + "#{raw(item.variant.name_to_display)}" + - if item.variant.options_text + = "(" + "#{raw(item.variant.options_text)}" + ")" + %br + %small + %em= raw(item.variant.product.supplier.name) + %td{:align => "right"} + = item.quantity + %td{:align => "right"} + = item.display_amount_with_adjustments + %tfoot + %tr + %td{:align => "right", :colspan => "2"} + Subtotal: + %td{:align => "right"} + = display_checkout_subtotal(@order) + - checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| + %tr + %td{:align => "right", :colspan => "2"} + = "#{raw(adjustment.label)}:" + %td{:align => "right"} + = adjustment.display_amount + %tr + %td{:align => "right", :colspan => "2"} + %strong Total: + %td{:align => "right"} + %strong= @order.display_total +%p   diff --git a/app/views/spree/order_mailer/_payment.html.haml b/app/views/spree/order_mailer/_payment.html.haml new file mode 100644 index 0000000000..41968ba1ad --- /dev/null +++ b/app/views/spree/order_mailer/_payment.html.haml @@ -0,0 +1,14 @@ +- if @order.payments.first.andand.payment_method.andand.type == "Spree::PaymentMethod::Check" and @order.payments.first.andand.payment_method.andand.description + %p.callout + %span{:style => "float:right;"} + - if @order.paid? + PAID + - else + NOT PAID + %strong Payment summary + %h4 + Paying via: + %strong= @order.payments.first.andand.payment_method.andand.name.andand.html_safe + %p + %em= @order.payments.first.andand.payment_method.andand.description.andand.html_safe + %p   diff --git a/app/views/spree/order_mailer/_shipping.html.haml b/app/views/spree/order_mailer/_shipping.html.haml new file mode 100644 index 0000000000..cb9cde72ca --- /dev/null +++ b/app/views/spree/order_mailer/_shipping.html.haml @@ -0,0 +1,59 @@ +- if @order.shipping_method.andand.require_ship_address + / Delivery details + %p.callout + %strong + - if @order.shipping_method.andand.name + #{@order.shipping_method.name.html_safe} + - else + Delivery details + + - if @order.order_cycle.andand.pickup_time_for(@order.distributor) + %h4 + Delivery on: + %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} + - if @order.shipping_method.andand.description + %p + %em #{@order.shipping_method.description.html_safe} + %br   + + - if @order.ship_address + %h4 Delivery address: + %p + #{@order.ship_address.full_name} + %br + #{@order.ship_address.full_address} + %br + #{@order.ship_address.phone} + %br   + + +- else + / Collection details + %p.callout + %strong + - if @order.shipping_method.andand.name + #{@order.shipping_method.name.html_safe} + - else + Collection details + + - if @order.order_cycle.andand.pickup_time_for(@order.distributor).present? + %h4 + Ready for collection: + %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} + + - if @order.shipping_method.andand.description.present? + %p + %em #{@order.shipping_method.description.html_safe} + %br   + + - if @order.ship_address.full_address + %p + %strong Collecting from: + %br + #{@order.ship_address.full_address} + + - if @order.order_cycle.andand.pickup_instructions_for(@order.distributor).present? + %p + %strong Collection instructions: + %br + #{@order.order_cycle.pickup_instructions_for(@order.distributor)} diff --git a/app/views/spree/order_mailer/_special_instructions.html.haml b/app/views/spree/order_mailer/_special_instructions.html.haml new file mode 100644 index 0000000000..5145260411 --- /dev/null +++ b/app/views/spree/order_mailer/_special_instructions.html.haml @@ -0,0 +1,7 @@ +- if @order.special_instructions.present? + %br + %p + %small + %strong Your notes: + %br + #{@order.special_instructions} diff --git a/app/views/spree/order_mailer/confirm_email_for_customer.html.haml b/app/views/spree/order_mailer/confirm_email_for_customer.html.haml index 4488c76edb..0816bd432d 100644 --- a/app/views/spree/order_mailer/confirm_email_for_customer.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_customer.html.haml @@ -23,135 +23,10 @@ Here are your order details from %strong= "#{@order.distributor.name}:" -%table.order-summary{:width => "100%"} - %thead - %tr - %th{:align => "left"} - %h4 Item - %th{:align => "right", :width => "25%"} - %h4 Qty - %th{:align => "right", :width => "25%"} - %h4 Price - %tbody - - @order.line_items.each do |item| - %tr - %td - - if item.variant.product.name == item.variant.name_to_display - %strong= "#{raw(item.variant.product.name)}" - - else - %strong - %span= "#{raw(item.variant.product.name)}" - %span= "- " + "#{raw(item.variant.name_to_display)}" - - if item.variant.options_text - = "(" + "#{raw(item.variant.options_text)}" + ")" - %br - %small - %em= raw(item.variant.product.supplier.name) - %td{:align => "right"} - = item.quantity - %td{:align => "right"} - = item.display_amount_with_adjustments - %tfoot - %tr - %td{:align => "right", :colspan => "2"} - Subtotal: - %td{:align => "right"} - = display_checkout_subtotal(@order) - - checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| - %tr - %td{:align => "right", :colspan => "2"} - = "#{raw(adjustment.label)}:" - %td{:align => "right"} - = adjustment.display_amount - %tr - %td{:align => "right", :colspan => "2"} - %strong Total: - %td{:align => "right"} - %strong= @order.display_total -%p   - -- if @order.payments.first.andand.payment_method.andand.type == "Spree::PaymentMethod::Check" and @order.payments.first.andand.payment_method.andand.description - %p.callout - %span{:style => "float:right;"} - - if @order.paid? - PAID - - else - NOT PAID - %strong Payment summary - %h4 - Paying via: - %strong= @order.payments.first.andand.payment_method.andand.name.andand.html_safe - %p - %em= @order.payments.first.andand.payment_method.andand.description.andand.html_safe - %p   - -- if @order.shipping_method.andand.require_ship_address - / Delivery details - %p.callout - %strong - - if @order.shipping_method.andand.name - #{@order.shipping_method.name.html_safe} - - else - Delivery details - - - if @order.order_cycle.andand.pickup_time_for(@order.distributor) - %h4 - Delivery on: - %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} - - if @order.shipping_method.andand.description - %p - %em #{@order.shipping_method.description.html_safe} - %br   - - - if @order.ship_address - %h4 Delivery address: - %p - #{@order.ship_address.full_name} - %br - #{@order.ship_address.full_address} - %br - #{@order.ship_address.phone} - %br   - - -- else - / Collection details - %p.callout - %strong - - if @order.shipping_method.andand.name - #{@order.shipping_method.name.html_safe} - - else - Collection details - - - if @order.order_cycle.andand.pickup_time_for(@order.distributor).present? - %h4 - Ready for collection: - %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} - - - if @order.shipping_method.andand.description.present? - %p - %em #{@order.shipping_method.description.html_safe} - %br   - - - if @order.ship_address.full_address - %p - %strong Collecting from: - %br - #{@order.ship_address.full_address} - - - if @order.order_cycle.andand.pickup_instructions_for(@order.distributor).present? - %p - %strong Collection instructions: - %br - #{@order.order_cycle.pickup_instructions_for(@order.distributor)} - -- if @order.special_instructions.present? - %br - %p - %small - %strong Your notes: - %br - #{@order.special_instructions} += render 'order_summary' += render 'payment' += render 'shipping' += render 'special_instructions' %br %p.callout diff --git a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml index fe48c1c6d1..f62b3cdfb4 100644 --- a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml @@ -23,134 +23,10 @@ %strong= "#{@order.bill_address.firstname} #{@order.bill_address.lastname}" completed the following order at your shopfront: -%table.order-summary{:width => "100%"} - %thead - %tr - %th{:align => "left"} - %h4 Item - %th{:align => "right", :width => "25%"} - %h4 Qty - %th{:align => "right", :width => "25%"} - %h4 Price - %tbody - - @order.line_items.each do |item| - %tr - %td - - if item.variant.product.name == item.variant.name_to_display - %strong= "#{raw(item.variant.product.name)}" - - else - %strong - %span= "#{raw(item.variant.product.name)}" - %span= "- " + "#{raw(item.variant.name_to_display)}" - - if item.variant.options_text - = "(" + "#{raw(item.variant.options_text)}" + ")" - %br - %small - %em= raw(item.variant.product.supplier.name) - %td{:align => "right"} - = item.quantity - %td{:align => "right"} - = item.display_amount_with_adjustments - %tfoot - %tr - %td{:align => "right", :colspan => "2"} - Subtotal: - %td{:align => "right"} - = display_checkout_subtotal(@order) - - checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| - %tr - %td{:align => "right", :colspan => "2"} - = "#{raw(adjustment.label)}:" - %td{:align => "right"} - = adjustment.display_amount - %tr - %td{:align => "right", :colspan => "2"} - %strong Total: - %td{:align => "right"} - %strong= @order.display_total -%p   - -- if @order.payments.first.andand.payment_method.andand.type == "Spree::PaymentMethod::Check" and @order.payments.first.andand.payment_method.andand.description - %p.callout - %span{:style => "float:right;"} - - if @order.paid? - PAID - - else - NOT PAID - %strong Payment summary - %h4 - Paying via: - %strong= @order.payments.first.andand.payment_method.andand.name.andand.html_safe - %p - %em= @order.payments.first.andand.payment_method.andand.description.andand.html_safe - %p   - -- if @order.shipping_method.andand.require_ship_address - / Delivery details - %p.callout - %strong - - if @order.shipping_method.andand.name - #{@order.shipping_method.name.html_safe} - - else - Delivery details - - - if @order.order_cycle.andand.pickup_time_for(@order.distributor) - %h4 - Delivery on: - %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} - - if @order.shipping_method.andand.description - %p - %em #{@order.shipping_method.description.html_safe} - %br   - - - if @order.ship_address - %h4 Delivery address: - %p - #{@order.ship_address.full_name} - %br - #{@order.ship_address.full_address} - %br - #{@order.ship_address.phone} - %br   - -- else - / Collection details - %p.callout - %strong - - if @order.shipping_method.andand.name - #{@order.shipping_method.name.html_safe} - - else - Collection details - - - if @order.order_cycle.andand.pickup_time_for(@order.distributor).present? - %h4 - Ready for collection: - %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} - - - if @order.shipping_method.andand.description.present? - %p - %em #{@order.shipping_method.description.html_safe} - %br   - - - if @order.ship_address.full_address - %p - %strong Collecting from: - %br - #{@order.ship_address.full_address} - - - if @order.order_cycle.andand.pickup_instructions_for(@order.distributor).present? - %p - %strong Collection instructions: - %br - #{@order.order_cycle.pickup_instructions_for(@order.distributor)} - -- if @order.special_instructions.present? - %br - %p - %small - %strong Customer notes: - %br - #{@order.special_instructions} += render 'order_summary' += render 'payment' += render 'shipping' += render 'special_instructions' %p   = render 'shared/mailers/signoff'