Skip to content

Commit

Permalink
added order recap after purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
guub committed Nov 11, 2016
1 parent 62072f1 commit 120629e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/carts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<tbody>
<% @cart_total = 0 %>
<% cart.each do |product_id, details| %>
<%= render 'item', product_id: product_id, details: details %>
<%= render 'itm', product_id: product_id, details: details %>
<% end %>
</tbody>
<tfoot>
Expand Down
25 changes: 25 additions & 0 deletions app/views/orders/_item.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<% quantity = line_item.quantity %>

<% if product = Product.find_by(id: line_item.product_id) %>
<% item_total = line_item.total_price %>
<% @cart_total += item_total %>
<tr>
<td>
<%= image_tag product.image.tiny %>
</td>
<td>
<h4><%= product.name %></h4>
<br>
<p><%= product.description %></p>
</td>
<td>
<%= product.price %>
</td>
<td>
<%= quantity %>
</td>
<td>
<%= item_total %>
</td>
</tr>
<% end %>
29 changes: 27 additions & 2 deletions app/views/orders/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,33 @@
<h1>Order #<%= @order.id %></h1>
</header>

<div class="order-summary jumbotron">
<h4>Thank you for your order!</h4>
<div class="panel panel-default items">
<table class="table table-bordered">
<thead>
<tr>
<th colspan="2">Product</th>
<th>Unit Price</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<% @cart_total = 0 %>
<% @order.line_items.each do |line_item| %>
<%= render 'item', line_item: line_item %>
<% end %>
</tbody>
<tfoot>
<tr>
<th colspan="4">
TOTAL:
</th>
<th>
<%= @cart_total %>
</th>
</tr>
</tfoot>
</table>
</div>

<%= link_to "Continue Shopping", root_path, class: 'btn btn-lg btn-primary' %>
Expand Down

0 comments on commit 120629e

Please sign in to comment.