Commit 5cb9a849 by Vy Quoc Vu

update cart

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