Commit 7a9b2700 by vulehuan

checkout function

parent b949c6f5
......@@ -59,6 +59,14 @@ class CardsController < ApplicationController
end
def checkout
add_breadcrumb "Checkout", url_for(action: 'checkout')
  • nếu là function có params thì phải bỏ trong dấu ()

Please register or sign in to reply
@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
def confirm_checkout
......
<table class="table table-hover">
<thead>
<tr>
<td>No.</td>
<td>Product name</td>
<td>Quantity</td>
<td>Price</td>
<td>Total</td>
<% if can_edit %>
<td>Action</td>
<% end %>
</tr>
</thead>
<tbody>
<% if card_infos.empty? || card_infos[:card_items].empty? %>
<tr><td colspan="6"><a href="<%= products_path %>">Click here to order</a></td></tr>
<%
else
card_items = card_infos[:card_items]
$i = 1
total = 0
card_items.each do |card_item|
product = Product.find(card_item[:product_id])
total += product.price
%>
<tr>
<td><%= $i %></td>
<td><%= link_to product.name, product_path(product) %></td>
<% if can_edit %>
<td><input type="text" class="form-control" value="<%= card_item[:quantity] %>" /></td>
<% else %>
<td><%= card_item[:quantity] %></td>
<% end %>
<td><%= number_with_delimiter(product.price) %></td>
<td><%= number_with_delimiter(product.price * card_item[:quantity]) %></td>
<% if can_edit %>
<td>
<a href="<%= cards_path %>?product_id=<%= card_item[:product_id] %>&card_action=remove" class="btn btn-default" dada="{:confirm=>"Do you want to remove this product?"}">Remove</a>
</td>
<% end %>
</tr>
<%
$i += 1
end
%>
<tr>
<td colspan="3">
</td>
<td colspan="<%= can_edit ? 3 : 2 %>">
<b><%= number_with_delimiter(total) %></b>
</td>
</tr>
<% if can_edit %>
<tr>
<td colspan="6">
<div class="text-center">
<input class="btn btn-default" type="submit" name="btn[update]" value="Update quantity" />
<a class="btn btn-primary" href="<%= url_for(action: 'checkout') %>">Check out</a>
</div>
</td>
</tr>
<% end %>
<%
end
%>
</tbody>
</table>
\ No newline at end of file
<h1>Cards#checkout</h1>
<p>Find me in app/views/cards/checkout.html.erb</p>
<% provide(:title, "Check out") %>
<div class="body-box">
<h2 class="sprite-2">
Check out<span class="sprite-2"></span>
</h2>
<%= form_tag do %>
<%= label_tag(:full_name, "Full name:") %>
<%= text_field_tag :full_name, nil, class: "form-control" %>
<%= label_tag(:email, "Email:") %>
<%= text_field_tag :email, nil, class: "form-control" %>
<%= label_tag(:phone, "Phone:") %>
<%= text_field_tag :phone, nil, class: "form-control" %>
<%= label_tag(:address, "Address:") %>
<%= text_field_tag :address, nil, class: "form-control" %>
<%= label_tag(:note, "Note:") %>
<%= text_area_tag :note, nil, class: "form-control", rows: 10, cols: 25 %>
<%= render partial: 'cards/item_list', locals: { card_infos: @card_infos, can_edit: false } %>
Please register or sign in to reply
<div class="text-center">
<%= submit_tag "Check out", class: 'btn btn-primary btn-submit' %>
</div>
<% end %>
</div>
......@@ -4,63 +4,7 @@
Cards<span class="sprite-2"></span>
</h2>
<form>
<table class="table table-hover">
<thead>
<tr>
<td>No.</td>
<td>Product name</td>
<td>Quantity</td>
<td>Price</td>
<td>Total</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<% if @card_infos.empty? || @card_infos[:card_items].empty? %>
<tr><td colspan="6"><a href="<%= products_path %>">Click here to order</a></td></tr>
<%
else
card_items = @card_infos[:card_items]
$i = 1
total = 0
card_items.each do |card_item|
product = Product.find(card_item[:product_id])
total += product.price
%>
<tr>
<td><%= $i %></td>
<td><%= link_to product.name, product_path(product) %></td>
<td><input type="text" class="form-control" value="<%= card_item[:quantity] %>" /></td>
<td><%= number_with_delimiter(product.price) %></td>
<td><%= number_with_delimiter(product.price * card_item[:quantity]) %></td>
<td>
<a href="<%= cards_path %>?product_id=<%= card_item[:product_id] %>&card_action=remove" class="btn btn-default" dada="{:confirm=>"Do you want to remove this product?"}">Remove</a>
</td>
</tr>
<%
$i += 1
end
%>
<tr>
<td colspan="3">
</td>
<td colspan="3">
<b><%= number_with_delimiter(total) %></b>
</td>
</tr>
<tr>
<td colspan="6">
<div class="text-center">
<input class="btn btn-default" type="submit" name="btn[update]" value="Update quantity" />
<a class="btn btn-primary" href="">Check out</a>
</div>
</td>
</tr>
<%
end
%>
</tbody>
</table>
</form>
<%= render partial: 'cards/item_list', locals: { card_infos: @card_infos, can_edit: true } %>
</form>
<div class="clearfix"></div>
</div>
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