Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venshop
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
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Nguyen Quoc Kien
venshop
Commits
d895a13f
Commit
d895a13f
authored
Aug 03, 2015
by
Nguyen Quoc Kien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify code carts
parent
4c67bd5c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
11 deletions
+23
-11
app/controllers/carts_controller.rb
+13
-9
app/models/cart.rb
+8
-0
app/views/admin/carts/_show_to_buyers.html.erb
+1
-1
app/views/admin/carts/_show_to_user_id.html.erb
+1
-1
No files found.
app/controllers/carts_controller.rb
View file @
d895a13f
class
CartsController
<
ApplicationController
class
CartsController
<
ApplicationController
def
new
def
new
@cart
=
Cart
.
new
@cart
=
Cart
.
new
end
end
...
@@ -7,15 +8,10 @@ class CartsController < ApplicationController
...
@@ -7,15 +8,10 @@ class CartsController < ApplicationController
total
=
0
total
=
0
@cart
=
Cart
.
new
(
cart_params
)
@cart
=
Cart
.
new
(
cart_params
)
@cart
.
save
@cart
.
save
if
current_user
@cart
.
add_user_id_and_status
(
current_user
)
@cart
.
update
(
user_id:
current_user
.
id
,
status:
"Checkout"
)
get_user_id
()
user_id
=
current_user
.
id
else
@cart
.
update
(
user_id:
""
,
status:
"Checkout"
)
user_id
=
'guess'
end
if
@cart
.
save
if
@cart
.
save
session
[
user_id
].
each
do
|
key
,
value
|
session
[
@
user_id
].
each
do
|
key
,
value
|
@product
=
Product
.
find
(
key
)
@product
=
Product
.
find
(
key
)
@cart_product
=
CartProduct
.
new
(
cart_id:
@cart
.
id
,
product_id:
key
.
to_i
,
number:
value
.
to_i
,
price:
@product
.
price
)
@cart_product
=
CartProduct
.
new
(
cart_id:
@cart
.
id
,
product_id:
key
.
to_i
,
number:
value
.
to_i
,
price:
@product
.
price
)
@cart_product
.
save
@cart_product
.
save
...
@@ -24,7 +20,7 @@ class CartsController < ApplicationController
...
@@ -24,7 +20,7 @@ class CartsController < ApplicationController
@cart
.
update
(
total_price:
total
)
@cart
.
update
(
total_price:
total
)
update_info_user
()
update_info_user
()
OrderNotifier
.
received
(
@cart
).
deliver
OrderNotifier
.
received
(
@cart
).
deliver
session
[
user_id
]
=
nil
session
[
@
user_id
]
=
nil
flash
[
:success
]
=
"Email to send"
flash
[
:success
]
=
"Email to send"
redirect_to
products_path
redirect_to
products_path
else
else
...
@@ -53,6 +49,14 @@ class CartsController < ApplicationController
...
@@ -53,6 +49,14 @@ class CartsController < ApplicationController
params
.
require
(
:cart
).
permit
(
:full_name
,
:email
,
:address
,
:phone
)
params
.
require
(
:cart
).
permit
(
:full_name
,
:email
,
:address
,
:phone
)
end
end
def
get_user_id
if
current_user
@user_id
=
current_user
.
id
else
@user_id
=
'guess'
end
end
def
update_info_user
def
update_info_user
if
user_signed_in?
if
user_signed_in?
user
=
User
.
find
(
current_user
.
id
)
user
=
User
.
find
(
current_user
.
id
)
...
...
app/models/cart.rb
View file @
d895a13f
...
@@ -14,6 +14,14 @@ class Cart < ActiveRecord::Base
...
@@ -14,6 +14,14 @@ class Cart < ActiveRecord::Base
before_save
:downcase_email
before_save
:downcase_email
def
add_user_id_and_status
(
current_user
)
if
current_user
self
.
update
(
user_id:
current_user
.
id
,
status:
"Checkout"
)
else
self
.
update
(
user_id:
""
,
status:
"Checkout"
)
end
end
private
private
def
downcase_email
def
downcase_email
...
...
app/views/admin/carts/_show_to_buyers.html.erb
View file @
d895a13f
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<%
@carts
.
each
do
|
cart
|
%>
<%
@carts
.
each
do
|
cart
|
%>
<%
cart_products
=
cart
.
cart_products
%>
<%
cart_products
=
cart
.
cart_products
%>
<tr>
<tr>
<td
colspan=
"4"
><h4><b>
Cart
:
<%=
cart
.
created_at
%>
</b></h4></td>
<td
colspan=
"4"
><h4><b>
Cart
<%=
cart
.
id
%>
:
<%=
cart
.
created_at
.
to_formatted_s
(
:long_ordinal
)
%>
</b></h4></td>
</tr>
</tr>
<%
cart_products
.
each
do
|
cart_product
|
%>
<%
cart_products
.
each
do
|
cart_product
|
%>
<tbody>
<tbody>
...
...
app/views/admin/carts/_show_to_user_id.html.erb
View file @
d895a13f
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<%
@carts_to_user
.
each
do
|
cart_to_user
|
%>
<%
@carts_to_user
.
each
do
|
cart_to_user
|
%>
<%
cart_products
=
cart_to_user
.
cart_products
%>
<%
cart_products
=
cart_to_user
.
cart_products
%>
<tr>
<tr>
<td
colspan=
"4"
><h4><b>
Cart
:
<%=
cart_to_user
.
created_at
%>
</b></h4></td>
<td
colspan=
"4"
><h4><b>
Cart
<%=
cart_to_user
.
id
%>
:
<%=
cart_to_user
.
created_at
.
to_formatted_s
(
:long_ordinal
)
%>
</b></h4></td>
</tr>
</tr>
<%
cart_products
.
each
do
|
cart_product
|
%>
<%
cart_products
.
each
do
|
cart_product
|
%>
<tbody>
<tbody>
...
...
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