Commit 8d3a2c4a by hades

card: send smtp mail

parent 55625ba6
......@@ -37,21 +37,25 @@ class CardsController < ApplicationController
redirect_to cards_path
else
card_items = @card_infos[:card_items]
card_items.each do |card_item, key|
found = false
card_items.each do |card_item|
# if a product exist in card
if card_item[:product_id] == params[:product_id]
card_item[:quantity] += 1
card_items[key] = card_item
@card_infos = { card_items: card_items, customer_info: @card_infos[:customer_info] }
session[:SHOPPING_CARD_SESSION_NAME] = @card_infos
redirect_to cards_path
# card_item[:quantity] += 1
# @card_infos = { card_items: card_items, customer_info: @card_infos[:customer_info] }
# session[:SHOPPING_CARD_SESSION_NAME] = @card_infos
# redirect_to cards_path
found = true
break
end
end
# if a product not exist in card
if !found
card_items.push({ product_id: params[:product_id], quantity: 1 })
customer_info = @card_infos[:customer_info]
@card_infos = { card_items: card_items, customer_info: customer_info }
session[:SHOPPING_CARD_SESSION_NAME] = @card_infos
end
redirect_to cards_path
end
end
......@@ -137,13 +141,14 @@ class CardsController < ApplicationController
note: customer_info[:note],
items: xml_data
)
session[:SHOPPING_CARD_SESSION_NAME] = nil
UserMailer.card_send_to_consignee(customer_info[:email], @card_infos).deliver
redirect_to url_for(action: 'thankyou')
end
end
def thankyou
add_breadcrumb "Thank out", url_for(action: 'thankyou')
session[:SHOPPING_CARD_SESSION_NAME] = nil
render :layout => "application_one_col"
end
end
class UserMailer < ActionMailer::Base
default from: "from@example.com"
def card_send_to_consignee(email, card_infos)
@card_infos = card_infos
mail(
to: email,
subject: 'Shopping information'
)
end
end
<table class="table">
<tr>
<td><b>Full name</b>:</td>
<td><%= customer_info[:full_name] %></td>
</tr>
<tr>
<td><b>Email</b>:</td>
<td><%= customer_info[:email] %></td>
</tr>
<tr>
<td><b>Phone</b>:</td>
<td><%= customer_info[:phone] %></td>
</tr>
<tr>
<td><b>Address</b>:</td>
<td><%= customer_info[:address] %></td>
</tr>
<tr>
<td><b>Note</b>:</td>
<td><%= customer_info[:note] %></td>
</tr>
</table>
\ No newline at end of file
......@@ -25,7 +25,7 @@
%>
<tr>
<td><%= $i %></td>
<td><%= link_to product.name, product_path(product) %></td>
<td><%= link_to product.name, product_url(product) %></td>
<% if can_edit %>
<td><input type="text" class="form-control" value="<%= card_item[:quantity] %>" /></td>
<% else %>
......
......@@ -5,28 +5,7 @@
</h2>
<p><br />Please check your information:</p>
<% customer_info = @card_infos[:customer_info] %>
<table class="table">
<tr>
<td><b>Full name</b>:</td>
<td><%= customer_info[:full_name] %></td>
</tr>
<tr>
<td><b>Email</b>:</td>
<td><%= customer_info[:email] %></td>
</tr>
<tr>
<td><b>Phone</b>:</td>
<td><%= customer_info[:phone] %></td>
</tr>
<tr>
<td><b>Address</b>:</td>
<td><%= customer_info[:address] %></td>
</tr>
<tr>
<td><b>Note</b>:</td>
<td><%= customer_info[:note] %></td>
</tr>
</table>
<%= render partial: 'cards/customer_info', locals: { customer_info: customer_info } %>
<%= render partial: 'cards/item_list', locals: { card_infos: @card_infos, can_edit: false } %>
<%= form_tag do %>
<div class="text-center">
......
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Venshop</title>
</head>
<body>
<% customer_info = @card_infos[:customer_info] %>
<p>
Hi <b><%= customer_info[:full_name] %></b>,<br /><br />
You or someone has been ordered on our website with the following information:
</p>
<%= render partial: 'cards/customer_info', locals: { customer_info: customer_info } %>
<%= render partial: 'cards/item_list', locals: { card_infos: @card_infos, can_edit: false } %>
</body>
</html>
\ No newline at end of file
......@@ -24,5 +24,6 @@ module VenshopApp
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.action_mailer.default_url_options = { host: 'localhost:3000' }
end
end
......@@ -9,5 +9,18 @@ RecaptchaMailhide.configure do |c|
c.public_key = '6LfDL-kSAAAAAG8JuwZhxLaT8X8iHZYpWu-7DAFe'
end
VenshopApp::Application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'alphaplus.vn',
user_name: 'coi.no.reply@gmail.com',
password: 'q5cE05OUwJ',
authentication: 'plain',
enable_starttls_auto: true
}
end
YAHOO_SHOPPING_DATA_APP_ID = 'dj0zaiZpPXpIMzBsMUQyTk55dSZkPVlXazlZWGxzYjNoWU0yVW1jR285TUEtLSZzPWNvbnN1bWVyc2VjcmV0Jng9MzI-'
YAHOO_SHOPPING_DATA_SECRECT = '45b3584021d48d65984b515a2cd23623a3ec90cc'
\ No newline at end of file
require "spec_helper"
describe UserMailer do
pending "add some examples to (or delete) #{__FILE__}"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment