Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
Venshop.v2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vy Quoc Vu
Venshop.v2
Commits
5cb9a849
Commit
5cb9a849
authored
Jul 28, 2015
by
Vy Quoc Vu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update cart
parent
51bdd56c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
18 deletions
+26
-18
app/controllers/cart_products_controller.rb
+2
-2
app/views/cart_products/_new.html.erb
+2
-1
app/views/cart_products/index.html.erb
+11
-3
app/views/carts/info.html.erb
+6
-2
app/views/products/index.html.erb
+3
-8
config/routes.rb
+2
-2
No files found.
app/controllers/cart_products_controller.rb
View file @
5cb9a849
...
@@ -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
...
...
app/views/cart_products/_new.html.erb
View file @
5cb9a849
...
@@ -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>
app/views/cart_products/index.html.erb
View file @
5cb9a849
<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
+
"$"
%>
...
...
app/views/carts/info.html.erb
View file @
5cb9a849
<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
-%>
app/views/products/index.html.erb
View file @
5cb9a849
...
@@ -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
%>
...
...
config/routes.rb
View file @
5cb9a849
...
@@ -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_product
s/clear'
=>
'cart_products#clear_cart_product
'
get
'cart_product
/clear'
=>
'cart_products#clear
'
get
'cart'
=>
'carts#info'
get
'cart'
=>
'carts#info'
get
'carts'
=>
'cart
s#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'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment