Order confirmation email contains distributor info

This commit is contained in:
Rohan Mitchell
2013-04-29 11:14:00 +10:00
parent 50f3455523
commit 06c285689e
3 changed files with 90 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
Dear <%= @order.bill_address.firstname %>,
Please review and retain the following order information for your records.
============================================================
Order Summary
============================================================
Order for: <%= @order.bill_address.full_name %>
<% @order.line_items.each do |item| %>
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
<% end %>
============================================================
Subtotal: <%= number_to_currency @order.item_total %>
<% @order.adjustments.each do |adjustment| %>
<%= raw(adjustment.label) %> <%= number_to_currency(adjustment.amount) %>
<% end %>
Order Total: <%= number_to_currency(@order.total) %>
<% if @order.payment_method.name.include? "EFT" %>
============================================================
Payment Details
============================================================
<%= @order.payment_method.description.html_safe %>
<% end %>
============================================================
Collection / Delivery Details
============================================================
<%= strip_tags @order.distributor.distributor_info %>
<%= @order.distributor.next_collection_at %>
Thank you for your business.

View File

@@ -1,5 +1,21 @@
module EnterprisesDistributorInfoRichTextFeature
class Engine < ::Rails::Engine
isolate_namespace EnterprisesDistributorInfoRichTextFeature
initializer 'enterprises_distributor_info_rich_text_feature.mailer', :after => :load_config_initializers do |app|
if ENV['OFW_DEPLOYMENT'] == 'local_organics'
::Spree::OrderMailer.class_eval do
def confirm_email(order, resend = false)
@order = order
subject = (resend ? "[#{t(:resend).upcase}] " : '')
subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{order.number}"
mail(:to => order.email,
:subject => subject,
:template_name => 'confirm_email_with_distributor_info')
end
end
end
end
end
end

View File

@@ -6,6 +6,10 @@ feature "enterprises distributor info as rich text" do
before(:each) do
ENV['OFW_DEPLOYMENT'] = 'local_organics'
# The deployment is not set to local_organics on Rails init, so these
# initializers won't run. Re-call them now that the deployment is set.
EnterprisesDistributorInfoRichTextFeature::Engine.initializers.each &:run
end
@@ -43,8 +47,10 @@ feature "enterprises distributor info as rich text" do
page.should have_selector "tr[data-hook='distributor_info'] td", text: 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
end
scenario "viewing distributor info" do
d = create(:distributor_enterprise, distributor_info: 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.', next_collection_at: 'Thursday 2nd May')
scenario "viewing distributor info", js: true do
setup_shipping_details
d = create(:distributor_enterprise, distributor_info: 'Chu ge sai yubi dan <strong>bisento</strong> tobi ashi yubi ge omote.', next_collection_at: 'Thursday 2nd May')
p = create(:product, :distributors => [d])
login_to_consumer_section
@@ -64,5 +70,39 @@ feature "enterprises distributor info as rich text" do
page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
page.should have_content 'Thursday 2nd May'
end
# -- Purchase email
complete_purchase_from_checkout_address_page
ActionMailer::Base.deliveries.length.should == 1
email = ActionMailer::Base.deliveries.last
email.body.should =~ /Chu ge sai yubi dan bisento tobi ashi yubi ge omote./
email.body.should =~ /Thursday 2nd May/
end
private
def setup_shipping_details
zone = create(:zone)
c = Spree::Country.find_by_name('Australia')
Spree::ZoneMember.create(:zoneable => c, :zone => zone)
create(:itemwise_shipping_method, zone: zone)
create(:payment_method, :description => 'Cheque payment method')
end
def complete_purchase_from_checkout_address_page
fill_in_fields('order_bill_address_attributes_firstname' => 'Joe',
'order_bill_address_attributes_lastname' => 'Luck',
'order_bill_address_attributes_address1' => '19 Sycamore Lane',
'order_bill_address_attributes_city' => 'Horse Hill',
'order_bill_address_attributes_zipcode' => '3213',
'order_bill_address_attributes_phone' => '12999911111')
select('Australia', :from => 'order_bill_address_attributes_country_id')
select('Victoria', :from => 'order_bill_address_attributes_state_id')
click_button 'Save and Continue'
click_button 'Save and Continue'
click_button 'Process My Order'
end
end