Commit 5cb9a849 by Vy Quoc Vu

update cart

parent 51bdd56c
...@@ -16,10 +16,10 @@ class CartProductsController < ApplicationController ...@@ -16,10 +16,10 @@ class CartProductsController < ApplicationController
else else
cart_product[id] = 1 cart_product[id] = 1
end end
redirect_to :action => :index redirect_to :back
end end
def clear_cart_product def clear
session[:cart] = nil session[:cart] = nil
redirect_to :action => :index redirect_to :action => :index
end end
......
...@@ -19,5 +19,6 @@ ...@@ -19,5 +19,6 @@
<br> <br>
<br> <br>
<h2> <%= number_to_currency(total/100.to_f, :unit => '$')%> </h2> <h2> <%= number_to_currency(total/100.to_f, :unit => '$')%> </h2>
<%= link_to "Checkout", "/cart", class: "btn btn-lg btn-danger"%> <%= link_to "Pay", "/cart", class: "btn btn-lg btn-danger"%>
<%= link_to "info", "/carts", class: "btn btn-lg btn-success"%>
</ul> </ul>
<h1>Your Cart</h1> <h1>Your Cart</h1>
<%= link_to "Empty Cart" ,'/cart_products/clear' %> <form class="navbar-left" >
<ul> <%= link_to "Empty Cart" ,'/cart_product/clear' %>
</form>
<form class=" navbar-right" >
<%= link_to "Back " ,root_path %>
</form>
<div>
<ul>
<% total = 0 %> <% total = 0 %>
<% if !@cart_product.nil? %> <% if !@cart_product.nil? %>
<% @cart_product.each do |id, quantity| %> <% @cart_product.each do |id, quantity| %>
...@@ -17,7 +23,9 @@ ...@@ -17,7 +23,9 @@
<% else %> <% else %>
<h3>Empty</h3> <h3>Empty</h3>
<% end -%> <% end -%>
</ul> </ul>
</div>
<div class="col-md-12"> <div class="col-md-12">
<nav> <nav>
<%=(total/100.to_f).to_s + "$" %> <%=(total/100.to_f).to_s + "$" %>
......
<h1>Cart info</h1> <% if !session[:cart].nil? %>
<ul> <h1>Cart info</h1>
<ul>
<% @total = 0 %> <% @total = 0 %>
<% cart_product.each do |id, quantity| %> <% cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %> <% product = Product.find_by_id(id) %>
...@@ -31,3 +32,6 @@ ...@@ -31,3 +32,6 @@
<% end %> <% end %>
</div> </div>
</div> </div>
<%else%>
<h1>Your Cart is Empty</h1>
<% end -%>
...@@ -4,16 +4,11 @@ ...@@ -4,16 +4,11 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="center jumbotron" style="padding-left: 35px;"> <div class="center jumbotron" style="padding-left: 35px;">
<%= image_tag(product.image, size: "180x230")%> <%= image_tag(product.image, size: "180x230")%>
<h6><%= truncate(product.name, length:15) %></h6> <h6><%= truncate(product.name, length:24) %></h6>
<%= (product.price/100.to_f).to_s + "$" %> <%= (product.price/100.to_f).to_s + "$" %>
</br> </br>
<div> <h6><%= link_to "Buy", "/cart_products/#{product.id}", class: "btn btn-lg btn-danger" %>
<h6 ><%= link_to "Buy", "/cart_products/#{product.id}", class: "btn btn-lg btn-danger" %> </h6> <%= link_to "Info", "/products/#{product.id}", class: "btn btn-lg btn-info" %> </h6>
</div>
<div>
<h6><%= link_to "Info", "/products/#{product.id}", class: "btn btn-lg btn-info" %> </h6>
</div>
</div> </div>
</div> </div>
<% end %> <% end %>
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
get 'products/:id' => 'products#show' get 'products/:id' => 'products#show'
get 'cart_products/:id' => 'cart_products#add' get 'cart_products/:id' => 'cart_products#add'
get 'cart_products/clear' => 'cart_products#clear_cart_product' get 'cart_product/clear' => 'cart_products#clear'
get 'cart' => 'carts#info' get 'cart' => 'carts#info'
get 'carts' => 'carts#new' get 'carts' => 'cart_products#index'
get 'carts/show' =>'carts#show' get 'carts/show' =>'carts#show'
post 'carts/create' => 'carts#create', as: 'create_cart' post 'carts/create' => 'carts#create', as: 'create_cart'
......
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