Skip to content

Commit

Permalink
Move eligible usage in order mailer views to legacy promos
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Jun 24, 2024
1 parent daeacb5 commit eb7d8a2
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 25 deletions.
2 changes: 1 addition & 1 deletion core/app/views/spree/order_mailer/cancel_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<td><%= t('.subtotal') %></td>
<td><%= @order.display_item_total %></td>
</tr>
<% @order.adjustments.eligible.each do |adjustment| %>
<% @order.adjustments.each do |adjustment| %>
<tr>
<td></td>
<td><%= sanitize(adjustment.label) %></td>
Expand Down
2 changes: 1 addition & 1 deletion core/app/views/spree/order_mailer/cancel_email.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<% end %>
============================================================
<%= t('.subtotal') %> <%= @order.display_item_total %>
<% @order.adjustments.eligible.each do |adjustment| %>
<% @order.adjustments.each do |adjustment| %>
<%= raw(adjustment.label) %> <%= adjustment.display_amount %>
<% end %>
<%= t('.total') %> <%= @order.display_total %>
10 changes: 5 additions & 5 deletions core/app/views/spree/order_mailer/confirm_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
</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| %>
<% if @order.all_adjustments.promotion.exists? %>
<% @order.all_adjustments.promotion.group_by(&:label).each do |label, adjustments| %>
<tr>
<td></td>
<td><%= t('spree.promotion') %> <%= label %>:</td>
Expand All @@ -48,16 +48,16 @@
<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| %>
<% if @order.all_adjustments.tax.exists? %>
<% @order.all_adjustments.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| %>
<% @order.adjustments.each do |adjustment| %>
<% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
<tr>
<td></td>
Expand Down
10 changes: 5 additions & 5 deletions core/app/views/spree/order_mailer/confirm_email.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
============================================================
<%= 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| %>
<% if @order.all_adjustments.promotion.exists? %>
<% @order.all_adjustments.promotion.group_by(&:label).each do |label, adjustments| %>
<%= t('spree.promotion') %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
<% end %>
<% end %>
Expand All @@ -22,13 +22,13 @@
<%= 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| %>
<% if @order.all_adjustments.tax.exists? %>
<% @order.all_adjustments.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| %>
<% @order.adjustments.each do |adjustment| %>
<% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
<%= adjustment.label %> <%= adjustment.display_amount %>
<% end %>
Expand Down
17 changes: 4 additions & 13 deletions core/spec/mailers/order_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,25 @@
expect(confirmation_email.body).not_to include("&quot;")
end

context "only shows eligible adjustments in emails" do
context "displays order 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'
label: 'Order Adjustment'
)
end

let!(:confirmation_email) { Spree::OrderMailer.confirm_email(order) }
let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) }

specify do
expect(confirmation_email.body).not_to include("Ineligible Adjustment")
expect(confirmation_email.parts.first.body).to include("Order Adjustment")
end

specify do
expect(cancel_email.body).not_to include("Ineligible Adjustment")
expect(cancel_email.parts.first.body).to include("Order Adjustment")
end
end

Expand Down
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>
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 %>
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>
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') %>
51 changes: 51 additions & 0 deletions legacy_promotions/spec/mailers/spree/order_mailer_spec.rb
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

0 comments on commit eb7d8a2

Please sign in to comment.