From 06c285689e95709e9de178f5b92fb1c638ceee4b Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Mon, 29 Apr 2013 11:14:00 +1000 Subject: [PATCH] Order confirmation email contains distributor info --- ...nfirm_email_with_distributor_info.text.erb | 32 ++++++++++++++ .../engine.rb | 16 +++++++ ...distributor_info_rich_text_feature_spec.rb | 44 ++++++++++++++++++- 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 lib/chili/enterprises_distributor_info_rich_text_feature/app/views/spree/order_mailer/confirm_email_with_distributor_info.text.erb diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/app/views/spree/order_mailer/confirm_email_with_distributor_info.text.erb b/lib/chili/enterprises_distributor_info_rich_text_feature/app/views/spree/order_mailer/confirm_email_with_distributor_info.text.erb new file mode 100644 index 0000000000..6df4f707a6 --- /dev/null +++ b/lib/chili/enterprises_distributor_info_rich_text_feature/app/views/spree/order_mailer/confirm_email_with_distributor_info.text.erb @@ -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. diff --git a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/engine.rb b/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/engine.rb index 6c7634e050..cc3763ce65 100644 --- a/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/engine.rb +++ b/lib/chili/enterprises_distributor_info_rich_text_feature/lib/enterprises_distributor_info_rich_text_feature/engine.rb @@ -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 diff --git a/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb b/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb index 34d56f409f..1d6e53ffc8 100644 --- a/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb +++ b/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb @@ -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 bisento 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