-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move eligible usage in order mailer views to legacy promos
- Loading branch information
Showing
10 changed files
with
250 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
legacy_promotions/app/views/spree/order_mailer/cancel_email.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<table> | ||
<tr> | ||
<td> | ||
<p class="lede"> | ||
<%= t('.dear_customer') %> | ||
</p> | ||
<p> | ||
<%= t('.instructions') %> | ||
</p> | ||
<p> | ||
<%= t('.order_summary_canceled') %> | ||
</p> | ||
<table> | ||
<% @order.line_items.each do |item| %> | ||
<tr> | ||
<td><%= item.variant.sku %></td> | ||
<td> | ||
<%= item.variant.product.name %> | ||
<%= item.variant.options_text -%> | ||
</td> | ||
<td>(<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %></td> | ||
</tr> | ||
<% end %> | ||
<tr> | ||
<td></td> | ||
<td><%= t('.subtotal') %></td> | ||
<td><%= @order.display_item_total %></td> | ||
</tr> | ||
<% @order.adjustments.eligible.each do |adjustment| %> | ||
<tr> | ||
<td></td> | ||
<td><%= sanitize(adjustment.label) %></td> | ||
<td><%= adjustment.display_amount %></td> | ||
</tr> | ||
<% end %> | ||
<tr> | ||
<td></td> | ||
<td><%= t('.total') %></td> | ||
<td><%= @order.display_total %></td> | ||
</tr> | ||
</table> | ||
</td> | ||
<td class="expander"></td> | ||
</tr> | ||
</table> |
16 changes: 16 additions & 0 deletions
16
legacy_promotions/app/views/spree/order_mailer/cancel_email.text.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%= t('.dear_customer') %> | ||
|
||
<%= t('.instructions') %> | ||
|
||
============================================================ | ||
<%= t('.order_summary_canceled') %> | ||
============================================================ | ||
<% @order.line_items.each do |item| %> | ||
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %> | ||
<% end %> | ||
============================================================ | ||
<%= t('.subtotal') %> <%= @order.display_item_total %> | ||
<% @order.adjustments.eligible.each do |adjustment| %> | ||
<%= raw(adjustment.label) %> <%= adjustment.display_amount %> | ||
<% end %> | ||
<%= t('.total') %> <%= @order.display_total %> |
84 changes: 84 additions & 0 deletions
84
legacy_promotions/app/views/spree/order_mailer/confirm_email.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<table> | ||
<tr> | ||
<td> | ||
<p class="lede"> | ||
<%= t('.dear_customer') %> | ||
</p> | ||
<p> | ||
<%= t('.instructions') %> | ||
</p> | ||
<p> | ||
<%= t('.order_summary') %> | ||
</p> | ||
<table> | ||
<% @order.line_items.each do |item| %> | ||
<tr> | ||
<td><%= item.variant.sku %></td> | ||
<td> | ||
<%= item.variant.product.name %> | ||
<%= item.variant.options_text -%> | ||
</td> | ||
<td>(<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %></td> | ||
</tr> | ||
<% end %> | ||
<tr> | ||
<td></td> | ||
<td> | ||
<%= t('.subtotal') %> | ||
</td> | ||
<td> | ||
<%= @order.display_item_total %> | ||
</td> | ||
</tr> | ||
<% if @order.line_item_adjustments.exists? %> | ||
<% if @order.all_adjustments.promotion.eligible.exists? %> | ||
<% @order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %> | ||
<tr> | ||
<td></td> | ||
<td><%= t('spree.promotion') %> <%= label %>:</td> | ||
<td><%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %></td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% @order.shipments.group_by { |s| s.selected_shipping_rate.try(:name) }.each do |name, shipments| %> | ||
<tr> | ||
<td></td> | ||
<td><%= t('spree.shipping') %> <%= name %>:</td> | ||
<td><%= Spree::Money.new(shipments.sum(&:total_before_tax), currency: @order.currency) %></td> | ||
</tr> | ||
<% end %> | ||
<% if @order.all_adjustments.eligible.tax.exists? %> | ||
<% @order.all_adjustments.eligible.tax.group_by(&:label).each do |label, adjustments| %> | ||
<tr> | ||
<td></td> | ||
<td><%= t('spree.tax') %> <%= label %>:</td> | ||
<td><%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %></td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
<% @order.adjustments.eligible.each do |adjustment| %> | ||
<% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %> | ||
<tr> | ||
<td></td> | ||
<td><%= adjustment.label %>:</td> | ||
<td><%= adjustment.display_amount %></td> | ||
</tr> | ||
<% end %> | ||
<tr> | ||
<td></td> | ||
<td> | ||
<%= t('.total') %> | ||
</td> | ||
<td> | ||
<%= @order.display_total %> | ||
</td> | ||
</tr> | ||
</table> | ||
<p> | ||
<%= t('.thanks') %> | ||
</p> | ||
</td> | ||
<td class="expander"></td> | ||
</tr> | ||
</table> |
38 changes: 38 additions & 0 deletions
38
legacy_promotions/app/views/spree/order_mailer/confirm_email.text.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<%= t('.dear_customer') %> | ||
|
||
<%= t('.instructions') %> | ||
|
||
============================================================ | ||
<%= t('.order_summary') %> | ||
============================================================ | ||
<% @order.line_items.each do |item| %> | ||
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %> | ||
<% end %> | ||
============================================================ | ||
<%= t('.subtotal') %> <%= @order.display_item_total %> | ||
<% if @order.line_item_adjustments.exists? %> | ||
<% if @order.all_adjustments.promotion.eligible.exists? %> | ||
<% @order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %> | ||
<%= t('spree.promotion') %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% @order.shipments.group_by { |s| s.selected_shipping_rate.try(:name) }.each do |name, shipments| %> | ||
<%= t('spree.shipping') %>: <%= name %> <%= Spree::Money.new(shipments.sum(&:total_before_tax), currency: @order.currency) %> | ||
<% end %> | ||
|
||
<% if @order.all_adjustments.eligible.tax.exists? %> | ||
<% @order.all_adjustments.eligible.tax.group_by(&:label).each do |label, adjustments| %> | ||
<%= t('spree.tax') %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% @order.adjustments.eligible.each do |adjustment| %> | ||
<% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %> | ||
<%= adjustment.label %> <%= adjustment.display_amount %> | ||
<% end %> | ||
============================================================ | ||
<%= t('.total') %> <%= @order.display_total %> | ||
|
||
<%= t('.thanks') %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Spree::OrderMailer, type: :mailer do | ||
let(:order) do | ||
order = create(:order) | ||
product = stub_model(Spree::Product, name: %{The "BEST" product}) | ||
variant = stub_model(Spree::Variant, product: product) | ||
price = stub_model(Spree::Price, variant: variant, amount: 5.00) | ||
store = FactoryBot.build :store, mail_from_address: "[email protected]", bcc_email: "[email protected]" | ||
line_item = stub_model(Spree::LineItem, variant: variant, order: order, quantity: 1, price: 4.99) | ||
allow(variant).to receive_messages(default_price: price) | ||
allow(order).to receive_messages(line_items: [line_item]) | ||
allow(order).to receive(:store).and_return(store) | ||
order | ||
end | ||
|
||
context "only shows eligible adjustments in emails" do | ||
before do | ||
create( | ||
:adjustment, | ||
adjustable: order, | ||
order: order, | ||
eligible: true, | ||
label: 'Eligible Adjustment' | ||
) | ||
|
||
create( | ||
:adjustment, | ||
adjustable: order, | ||
order: order, | ||
eligible: false, | ||
label: 'Ineligible Adjustment' | ||
) | ||
end | ||
|
||
let!(:confirmation_email) { Spree::OrderMailer.confirm_email(order) } | ||
let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) } | ||
|
||
specify do | ||
expect(confirmation_email.parts.first.body).to include("Eligible Adjustment") | ||
expect(confirmation_email.parts.first.body).not_to include("Ineligible Adjustment") | ||
end | ||
|
||
specify do | ||
expect(cancel_email.parts.first.body).to include("Eligible Adjustment") | ||
expect(cancel_email.parts.first.body).not_to include("Ineligible Adjustment") | ||
end | ||
end | ||
end |