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
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
huanvl
venshop
Commits
2ddb6d64
Commit
2ddb6d64
authored
Oct 24, 2013
by
vulehuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove product function
parent
688d4832
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
venshop_app/app/controllers/cards_controller.rb
+20
-0
venshop_app/app/views/cards/index.html.erb
+2
-2
No files found.
venshop_app/app/controllers/cards_controller.rb
View file @
2ddb6d64
...
...
@@ -7,6 +7,25 @@ class CardsController < ApplicationController
@card_infos
=
session
[
:SHOPPING_CARD_SESSION_NAME
]
end
if
params
[
:product_id
]
!=
nil
# if remove a product from card
if
params
[
:card_action
]
!=
nil
&&
params
[
:card_action
]
==
'remove'
# Nothing to delete
if
@card_infos
.
empty?
redirect_to
cards_path
else
card_items
=
@card_infos
[
:card_items
]
card_items
.
each
do
|
card_item
,
key
|
# if a product exist in card
if
card_item
[
:product_id
]
==
params
[
:product_id
]
card_items
.
delete
(
card_item
)
@card_infos
=
{
card_items:
card_items
,
customer_info:
@card_infos
[
:customer_info
]
}
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
redirect_to
cards_path
end
end
end
else
# if add a product to card
# first time add to card
if
@card_infos
.
empty?
product
=
Product
.
find
(
params
[
:product_id
])
...
...
@@ -37,6 +56,7 @@ class CardsController < ApplicationController
end
end
end
end
def
checkout
end
...
...
venshop_app/app/views/cards/index.html.erb
View file @
2ddb6d64
...
...
@@ -16,7 +16,7 @@
</tr>
</thead>
<tbody>
<%
if
@card_infos
.
empty?
%>
<%
if
@card_infos
.
empty?
||
@card_infos
[
:card_items
].
empty?
%>
<tr><td
colspan=
"6"
><a
href=
"
<%=
products_path
%>
"
>
Click here to order
</a></td></tr>
<%
else
...
...
@@ -34,7 +34,7 @@
<td>
<%=
number_with_delimiter
(
product
.
price
)
%>
</td>
<td>
<%=
number_with_delimiter
(
product
.
price
*
card_item
[
:quantity
])
%>
</td>
<td>
<a
href=
"
"
class=
"btn btn-default
"
>
Remove
</a>
<a
href=
"
<%=
cards_path
%>
?product_id=
<%=
card_item
[
:product_id
]
%>
&card_action=remove"
class=
"btn btn-default"
dada=
"{:confirm=>"
Do
you
want
to
remove
this
product
?"}
"
>
Remove
</a>
</td>
</tr>
<%
...
...
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