Skip to content

Commit ac5efbc

Browse files
committed
Fixed some things
1 parent ccba9ee commit ac5efbc

6 files changed

Lines changed: 113 additions & 52 deletions

File tree

app/controllers/orders_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def show
1111

1212
def new
1313
@order = Order.new
14+
@cart = @current_cart
1415
end
1516

1617
def create

app/views/carts/show.html.erb

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1 @@
1-
<div class="center jumbotron">
2-
<p>
3-
Your Card => Total Items (<%= @cart.line_items.count %>)
4-
</p>
5-
<ul class="users">
6-
<% @cart.line_items.each do |line_item| %>
7-
<%= render line_item.product %>
8-
<li>Quantity:
9-
<%= line_item.quantity %>
10-
| Total Price:
11-
<%= number_to_currency(line_item.total_price) %>
12-
<!-- See lineItem section below for explanation of line_item links -->
13-
<ul>
14-
<!-- <li> -->
15-
<!-- <%#= link_to "Add one", line_item_add_path(:id => line_item), method: :post %> -->
16-
17-
<!-- reduce -->
18-
<%=link_to line_item_reduce_path(:id => line_item) , method: :post, class: "btn btn-danger" , style: "margin-top:15px;" do %>
19-
<i class="glyphicon glyphicon-minus" style="color:black;"></i>
20-
Reduce
21-
<% end %>
22-
23-
<!-- add -->
24-
<%=link_to line_item_add_path(:id => line_item) , method: :post , class: "btn btn-success" , style: "margin-top:15px;" do %>
25-
<i class="glyphicon glyphicon-plus" style="color:black;"></i>
26-
Add
27-
<% end %>
28-
29-
<!-- Remove -->
30-
<%=link_to line_item_path(line_item) ,method: :delete ,class: "btn btn-warning" , style: "margin-top:15px;" do %>
31-
<i class="glyphicon glyphicon-remove" style="color:black;"></i>
32-
Remove Item
33-
<% end %>
34-
35-
<!-- <%#= link_to "Reduce one", line_item_reduce_path(:id => line_item), method: :post %> -->
36-
<!-- </li> -->
37-
<!-- <li> -->
38-
<%#= link_to "Remove item", line_item_path(line_item), method: :delete %>
39-
<!-- </li> -->
40-
<hr />
41-
</ul>
42-
43-
<% end %>
44-
</ul>
45-
<h3>Total price:
46-
<%= number_to_currency(@cart.sub_total) %></h3>
47-
<!-- See Order section below for explanation of new_order_path -->
48-
<%= link_to "Empty cart", cart_path(@current_cart),method: :delete, data: {confirm: "Are you sure?"} %>
49-
|
50-
<%= link_to "Proceed to checkout", new_order_path %>
51-
</div>
1+
<%= render 'shared/cart' %>

app/views/orders/new.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<p>
1212
<%= f.submit "Finish Order"%>
1313
</p>
14-
<% end %>
1514

15+
<%= render 'shared/cart2' , :cart => @cart %>
16+
<% end %>
1617
</div>

app/views/shared/_cart.html.erb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<div class="center jumbotron">
2+
<p>
3+
Your Card => Total Items (<%= @cart.line_items.count %>)
4+
</p>
5+
<ul class="users">
6+
<% @cart.line_items.each do |line_item| %>
7+
<%= render 'shared/product' , :product => line_item.product %>
8+
<li>Quantity:
9+
<%= line_item.quantity %>
10+
| Total Price:
11+
<%= number_to_currency(line_item.total_price) %>
12+
<!-- See lineItem section below for explanation of line_item links -->
13+
<ul>
14+
<!-- <li> -->
15+
<!-- <%#= link_to "Add one", line_item_add_path(:id => line_item), method: :post %> -->
16+
17+
<!-- reduce -->
18+
<%=link_to line_item_reduce_path(:id => line_item) , method: :post, class: "btn btn-danger" , style: "margin-top:15px;" do %>
19+
<i class="glyphicon glyphicon-minus" style="color:black;"></i>
20+
Reduce
21+
<% end %>
22+
23+
<!-- add -->
24+
<%=link_to line_item_add_path(:id => line_item) , method: :post , class: "btn btn-success" , style: "margin-top:15px;" do %>
25+
<i class="glyphicon glyphicon-plus" style="color:black;"></i>
26+
Add
27+
<% end %>
28+
29+
<!-- Remove -->
30+
<%=link_to line_item_path(line_item) ,method: :delete ,class: "btn btn-warning" , style: "margin-top:15px;" do %>
31+
<i class="glyphicon glyphicon-remove" style="color:black;"></i>
32+
Remove Item
33+
<% end %>
34+
35+
<!-- <%#= link_to "Reduce one", line_item_reduce_path(:id => line_item), method: :post %> -->
36+
<!-- </li> -->
37+
<!-- <li> -->
38+
<%#= link_to "Remove item", line_item_path(line_item), method: :delete %>
39+
<!-- </li> -->
40+
<hr/>
41+
</ul>
42+
43+
<% end %>
44+
</ul>
45+
<h3>Total price:
46+
<%= number_to_currency(@cart.sub_total) %></h3>
47+
48+
<% if(@current_cart.line_items.count !=0 ) %>
49+
50+
<!-- See Order section below for explanation of new_order_path -->
51+
<%= link_to "Empty cart", cart_path(@current_cart),method: :delete, data: {confirm: "Are you sure?"} %>
52+
|
53+
<%= link_to "Proceed to checkout", new_order_path %>
54+
<% end %>
55+
</div>

app/views/shared/_cart2.html.erb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class="center jumbotron">
2+
<p>
3+
<h3>Total price:
4+
<%= number_to_currency(@cart.sub_total) %></h3>
5+
</p>
6+
<ul class="users">
7+
<% @cart.line_items.each do |line_item| %>
8+
<%= render 'shared/product' , :product => line_item.product %>
9+
<li>Quantity:
10+
<%= line_item.quantity %>
11+
| Total Price:
12+
<%= number_to_currency(line_item.total_price) %>
13+
<!-- See lineItem section below for explanation of line_item links -->
14+
15+
<hr/>
16+
<% end %>
17+
</ul>
18+
19+
</div>

app/views/shared/_product.html.erb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<li>
2+
3+
<%= link_to product do%>
4+
<% if product.picture? %>
5+
<%= image_tag product.picture.url %>
6+
<% else %>
7+
<%= image_tag "no_image.png", size:"150x150" %>
8+
<%end%>
9+
<%end %>
10+
11+
<strong>
12+
Name :
13+
</strong>
14+
<%= product.name %>
15+
,<strong>
16+
Description :
17+
</strong>
18+
<%= product.description %>
19+
<strong>
20+
Price :
21+
</strong>
22+
<%= product.price %> $
23+
24+
25+
<p>
26+
27+
<!-- Only Admin is allowed to modify products -->
28+
<% if logged_in? && current_user.admin? %>
29+
<%= link_to 'Edit', edit_product_path(product) %>
30+
or
31+
<%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %>
32+
<% end %>
33+
34+
</p>
35+
</li>

0 commit comments

Comments
 (0)