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
43e93f27
Commit
43e93f27
authored
Jul 28, 2015
by
Nguyen Quoc Kien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aaa
parent
d38dc405
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletions
+24
-1
app/controllers/application_controller.rb
+0
-1
app/controllers/carts_controller.rb
+24
-0
No files found.
app/controllers/application_controller.rb
View file @
43e93f27
...
...
@@ -16,7 +16,6 @@ class ApplicationController < ActionController::Base
@cart
=
Cart
.
create
()
end
session
[
:cart_id
]
=
@cart
.
id
end
def
configure_permitted_parameters
...
...
app/controllers/carts_controller.rb
View file @
43e93f27
...
...
@@ -43,4 +43,28 @@ class CartsController < ApplicationController
def
find_card
@cart
=
Cart
.
find
(
params
[
:id
])
end
def
add_product_to_cart
(
product_id
,
quantity
)
quantity
||=
1
product_id
=
product_id
.
to_s
current_quantity
=
cart_products_hash
.
fetch
(
product_id
,
{}).
fetch
(
'quantity'
,
0
)
quantity
+=
current_quantity
cart_products_hash
[
product_id
]
=
{
'quantity'
=>
quantity
}
end
def
remove_product_from_cart
(
product_id
)
product_id
=
product_id
.
to_s
cart_products_hash
.
delete
(
product_id
)
end
def
cart_hash
@session
[
'cart'
]
end
def
cart_products_hash
@session
[
'cart'
][
'products'
]
end
end
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