Commit 6a645571 by hades

checkout and confirm page

parent 7a9b2700
...@@ -452,6 +452,12 @@ footer { ...@@ -452,6 +452,12 @@ footer {
font-weight: bold; font-weight: bold;
} }
} }
thead {
.body-box {
form {
margin: 10px 0;
}
thead {
font-weight: bold; font-weight: bold;
}
} }
\ No newline at end of file
...@@ -67,9 +67,55 @@ class CardsController < ApplicationController ...@@ -67,9 +67,55 @@ class CardsController < ApplicationController
if @card_infos.empty? if @card_infos.empty?
redirect_to cards_path redirect_to cards_path
end end
if request.post?
@errors = Array.new
customer_info = Hash.new
if params[:full_name].empty?
@errors.push("Full name is required")
end
if params[:email].empty?
@errors.push("Email is required")
else
if params[:email] !~ /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
@errors.push("Invalid email address")
end
end
if params[:phone].empty?
@errors.push("Phone is required")
end
if params[:address].empty?
@errors.push("Address is required")
end
if @errors.count == 0
customer_info[:full_name] = params[:full_name]
customer_info[:email] = params[:email]
customer_info[:phone] = params[:phone]
customer_info[:address] = params[:address]
customer_info[:note] = params[:note]
@card_infos = { card_items: @card_infos[:card_items], customer_info: customer_info }
session[:SHOPPING_CARD_SESSION_NAME] = @card_infos
redirect_to url_for(action: 'confirm_checkout')
end
else
customer_info = @card_infos[:customer_info]
params[:full_name] = customer_info[:full_name]
params[:email] = customer_info[:email]
params[:phone] = customer_info[:phone]
params[:address] = customer_info[:address]
params[:note] = customer_info[:note]
end
end end
def confirm_checkout def confirm_checkout
add_breadcrumb "Checkout", url_for(action: 'checkout')
add_breadcrumb "Confirm", url_for(action: 'confirm_checkout')
@card_infos = Hash.new
if session[:SHOPPING_CARD_SESSION_NAME] != nil
@card_infos = session[:SHOPPING_CARD_SESSION_NAME]
end
if @card_infos.empty?
redirect_to cards_path
end
end end
def thankyou def thankyou
......
...@@ -4,19 +4,30 @@ ...@@ -4,19 +4,30 @@
Check out<span class="sprite-2"></span> Check out<span class="sprite-2"></span>
</h2> </h2>
<%= form_tag do %> <%= form_tag do %>
<% if @errors != nil %>
<div class="alert alert-error">
The form contains <%= pluralize(@errors.count, "error") %>.
<ul>
<% @errors.each do |error| %>
<li><%= error %></li>
<% end %>
</ul>
</div>
<% end %>
<%= label_tag(:full_name, "Full name:") %> <%= label_tag(:full_name, "Full name:") %>
<%= text_field_tag :full_name, nil, class: "form-control" %> <%= text_field_tag :full_name, params[:full_name], class: "form-control" %>
<%= label_tag(:email, "Email:") %> <%= label_tag(:email, "Email:") %>
<%= text_field_tag :email, nil, class: "form-control" %> <%= text_field_tag :email, params[:email], class: "form-control" %>
<%= label_tag(:phone, "Phone:") %> <%= label_tag(:phone, "Phone:") %>
<%= text_field_tag :phone, nil, class: "form-control" %> <%= text_field_tag :phone, params[:phone], class: "form-control" %>
<%= label_tag(:address, "Address:") %> <%= label_tag(:address, "Address:") %>
<%= text_field_tag :address, nil, class: "form-control" %> <%= text_field_tag :address, params[:address], class: "form-control" %>
<%= label_tag(:note, "Note:") %> <%= label_tag(:note, "Note:") %>
<%= text_area_tag :note, nil, class: "form-control", rows: 10, cols: 25 %> <%= text_area_tag :note, params[:note], class: "form-control", rows: 10, cols: 25 %>
<%= render partial: 'cards/item_list', locals: { card_infos: @card_infos, can_edit: false } %> <%= render partial: 'cards/item_list', locals: { card_infos: @card_infos, can_edit: false } %>
<div class="text-center"> <div class="text-center">
<%= submit_tag "Check out", class: 'btn btn-primary btn-submit' %> <a href="<%= cards_path %>" class="btn btn-default">Back</a>
<%= submit_tag "Continue", class: 'btn btn-primary btn-submit' %>
</div> </div>
<% end %> <% end %>
</div> </div>
<h1>Cards#confirm_checkout</h1> <% provide(:title, "Confirmation") %>
<p>Find me in app/views/cards/confirm_checkout.html.erb</p> <div class="body-box">
<h2 class="sprite-2">
Confirmation<span class="sprite-2"></span>
</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>Email:</td>
<td><%= customer_info[:email] %></td>
</tr>
<tr>
<td>Phone:</td>
<td><%= customer_info[:phone] %></td>
</tr>
<tr>
<td>Address:</td>
<td><%= customer_info[:address] %></td>
</tr>
<tr>
<td>Note:</td>
<td><%= customer_info[:note] %></td>
</tr>
</table>
<%= render partial: 'cards/item_list', locals: { card_infos: @card_infos, can_edit: false } %>
<div class="text-center">
The information above
<a href="<%= url_for(action: 'checkout') %>" class="btn btn-default">Incorrect, click here</a>
<%= submit_tag "Correct, click here", class: 'btn btn-primary btn-submit' %>
</div>
</div>
...@@ -4,6 +4,7 @@ VenshopApp::Application.routes.draw do ...@@ -4,6 +4,7 @@ VenshopApp::Application.routes.draw do
get "products/show" get "products/show"
get "cards/index" get "cards/index"
get "cards/checkout" get "cards/checkout"
post "cards/checkout"
get "cards/confirm_checkout" get "cards/confirm_checkout"
get "cards/thankyou" get "cards/thankyou"
resources :users resources :users
......
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