Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

emails - notifier

  • Loading branch information...
commit 04c7f3cd314bd207cd253d2d7ec90149bd3acda4 1 parent 348b976
Wenbert Del Rosario authored
1  app/controllers/orders_controller.rb
View
@@ -56,6 +56,7 @@ def create
if @order.save
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
+ Notifier.order_received(@order).deliver
format.html { redirect_to(store_url, :notice =>
'Thank you for your order.') }
format.xml { render :xml => @order}
24 app/mailers/notifier.rb
View
@@ -0,0 +1,24 @@
+class Notifier < ActionMailer::Base
+ default from: "Wenbert Del Rosario <wenbert@gmail.com>"
+
+ # Subject can be set in your I18n file at config/locales/en.yml
+ # with the following lookup:
+ #
+ # en.notifier.order_received.subject
+ #
+ def order_received(order)
+ @order = order
+ mail to: order.email, :subject => 'Book store order confirmation'
+ end
+
+ # Subject can be set in your I18n file at config/locales/en.yml
+ # with the following lookup:
+ #
+ # en.notifier.order_shipped.subject
+ #
+ def order_shipped(order)
+ @order = order
+ mail :to => order.email, :subject => 'Pragmatic Store Order Shipped'
+ end
+
+end
4 app/views/line_items/_line_item.text.erb
View
@@ -0,0 +1,4 @@
+<%= sprintf("%2d x %s",
+line_item.quantity,
+truncate(line_item.product.title, :length => 50)) %>
+
9 app/views/notifier/order_received.text.erb
View
@@ -0,0 +1,9 @@
+Dear <%= @order.name %>
+
+Thank you for your recent order from the Store.
+
+You ordered the following items:
+
+<%= render @order.line_items %>
+
+We'll send you a separate email when your order ships.
9 app/views/notifier/order_shipped.html.erb
View
@@ -0,0 +1,9 @@
+<h3>Pragmatic Order Shipped</h3>
+<p>
+This is just to let you know that we've shipped your recent order:
+</p>
+<table>
+<tr><th colspan="2" >Qty</th><th>Description</th></tr>
+<%= render @order.line_items %>
+</table>
+
3  app/views/notifier/order_shipped.text.erb
View
@@ -0,0 +1,3 @@
+Notifier#order_shipped
+
+<%= @greeting %>, find me in app/views/app/views/notifier/order_shipped.text.erb
2  config/environments/development.rb
View
@@ -27,4 +27,6 @@
# Expands the lines which load the assets
config.assets.debug = true
+
+ config.action_mailer.delivery_method = :test
end
21 test/functional/notifier_test.rb
View
@@ -0,0 +1,21 @@
+require 'test_helper'
+
+class NotifierTest < ActionMailer::TestCase
+ test "order_received" do
+ mail = Notifier.order_received(orders(:one))
+ assert_equal "Pragmatic Store Order Confirmation", mail.subject
+ assert_equal ["dave@example.org"], mail.to
+ assert_equal ["depot@example.com"], mail.from
+ assert_match /1 x Programming Ruby 1.9/, mail.body.encoded
+ end
+
+ test "order_shipped" do
+ mail = Notifier.order_shipped(orders(:one))
+ assert_equal "Pragmatic Store Order Shipped", mail.subject
+ assert_equal ["dave@example.org"], mail.to
+ assert_equal ["depot@example.com"], mail.from
+ assert_match /<td>1&times;<\/td>\s*<td>Programming Ruby 1.9<\/td>/,
+ mail.body.encoded
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.