Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
Ecsite
Project
Project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shoei.kanno
Ecsite
Commits
aad90608
Commit
aad90608
authored
Oct 21, 2020
by
DESKTOP-FI5PFC1\tevir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
カート機能修正
parent
b3f409e5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
10 deletions
+36
-10
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+13
-6
application.properties
src/main/resources/application.properties
+1
-1
cart.js
src/main/resources/static/js/cart.js
+19
-1
list.js
src/main/resources/static/js/list.js
+1
-0
cart.html
src/main/resources/templates/cart.html
+2
-2
No files found.
src/main/java/com/example/api/EcsiteRestController.java
View file @
aad90608
...
...
@@ -70,7 +70,7 @@ public class EcsiteRestController {
//カート追加処理
@PostMapping
(
"inputCart"
)
public
void
inputCart
(
@RequestBody
ItemData
data
,
Model
model
,
Shoes
shoes
)
{
public
LinkedHashMap
<
String
,
Items
>
inputCart
(
@RequestBody
ItemData
data
,
Model
model
,
Shoes
shoes
)
{
//靴の在庫数を購入予定数が超えていないか確認
shoes
=
shoesService
.
findOne
(
data
.
getShoesId
());
if
(
shoes
.
getStock
()
<
data
.
getQuantity
()){
...
...
@@ -89,10 +89,11 @@ public class EcsiteRestController {
//カートのアイテム数をセッションに追加
session
.
setAttribute
(
"cartValue"
,
data
.
getQuantity
());
//セッションがnull出ない場合
return
cart
;
}
else
{
//HashMapを生成
ArrayList
<
String
>
list
=
new
ArrayList
<
String
>
();
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
ArrayList
<
String
>
list
=
new
ArrayList
<
String
>
();
String
id
=
data
.
getShoesId
().
toString
();
//生成したHashMapにセッションにもともとある情報を照会させる。
cart
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
...
...
@@ -100,9 +101,10 @@ public class EcsiteRestController {
cart
.
forEach
((
key
,
value
)
->{
if
(
key
.
equals
(
id
)){
sameId
=
key
;
System
.
out
.
println
(
sameId
);
}
});
if
(
sameId
.
equals
(
i
d
)){
if
(
id
.
equals
(
sameI
d
)){
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()
+
cart
.
get
(
id
).
getQuantity
()));
}
else
{
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
...
...
@@ -112,18 +114,23 @@ public class EcsiteRestController {
int
nowQuantity
=
(
int
)
session
.
getAttribute
(
"cartValue"
);
//カートのアイテム数をセッションに追加
session
.
setAttribute
(
"cartValue"
,
nowQuantity
+
data
.
getQuantity
());
return
cart
;
}
}
@PostMapping
(
"editCart"
)
public
void
editCart
(
@RequestBody
ItemData
data
,
Shoes
shoes
)
{
System
.
out
.
println
(
data
.
getQuantity
());
public
LinkedHashMap
<
String
,
Items
>
editCart
(
@RequestBody
ItemData
data
,
Shoes
shoes
)
{
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
String
id
=
data
.
getShoesId
().
toString
();
//生成したHashMapにセッションにもともとある情報を照会させる。
cart
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
if
(
data
.
getQuantity
()
==
0
)
{
cart
.
remove
(
id
);
}
else
{
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
}
session
.
setAttribute
(
"cart"
,
cart
);
return
cart
;
}
@GetMapping
(
"buy"
)
...
...
src/main/resources/application.properties
View file @
aad90608
spring.datasource.url
=
jdbc:mysql://localhost:3306/limited
spring.datasource.username
=
root
spring.datasource.password
=
spring.datasource.password
=
kanikani7
security.basic.enabled
=
false
spring.datasource.driverClassName
=
com.mysql.jdbc.Driver
src/main/resources/static/js/cart.js
View file @
aad90608
//buyボタン表示・非表示
if
(
$
(
'#total-price-span'
).
text
()
===
"¥0"
){
$
(
'.js-modal-open'
).
hide
();
}
else
{
$
(
'.js-modal-open'
).
show
();
}
//cart個数
let
cartValue
=
0
;
for
(
let
i
=
0
;
i
<
$
(
'.itemCount'
).
length
;
i
++
){
cartValue
+=
Number
(
$
(
'.itemCount'
).
eq
(
i
).
val
());
}
$
(
'.shoping-cart'
).
text
(
cartValue
);
//モーダル表示
$
(
function
(){
$
(
'.js-modal-open'
).
on
(
'click'
,
function
(){
...
...
@@ -42,7 +57,10 @@ $('.itemCountChange').on('click', function(event){
dataType
:
"json"
,
data
:
JSON
.
stringify
(
data
)
})
window
.
location
.
href
=
"/limited/cart"
;
.
done
(
function
(){
window
.
location
.
href
=
"/limited/cart"
;
});
//[#modal-content]と[#modal-overlay]をフェードアウトした後に…
$
(
"#modal-content,#modal-overlay"
).
fadeOut
(
"slow"
,
function
(){
...
...
src/main/resources/static/js/list.js
View file @
aad90608
...
...
@@ -103,6 +103,7 @@ $('.cartBtn').on('click', function(event){
dataType
:
"json"
,
data
:
JSON
.
stringify
(
data
)
})
//[#modal-content]と[#modal-overlay]をフェードアウトした後に…
$
(
"#modal-content,#modal-overlay"
).
fadeOut
(
"slow"
,
function
(){
//[#modal-overlay]を削除する
...
...
src/main/resources/templates/cart.html
View file @
aad90608
...
...
@@ -66,7 +66,7 @@
<li><a
th:href=
"@{/limited/top}"
>
Home
</a></li>
<li><a
th:href=
"@{/limited/list}"
>
Shop
</a></li>
<li><a
th:href=
"@{/limited/log/{id}(id=${user.id})}"
>
My Purchase Log
</a></li>
<li
class=
"active"
><a
th:href=
"@{/limited/wallets/{id}(id=${user.id})}"
>
Wallets
</a></li>
<li><a
th:href=
"@{/limited/wallets/{id}(id=${user.id})}"
>
Wallets
</a></li>
</ul>
<ul
class=
"nav navbar-nav navbar-right cart-menu"
>
<li><a
class=
"search-btn"
><i
class=
"fa fa-search"
aria-hidden=
"true"
></i></a></li>
...
...
@@ -113,7 +113,7 @@
<td
class=
"hidden"
><input
th:text=
"${cart.shoesId}"
/></td>
<td
class=
"tdCart"
><img
th:src=
"@{/upload/{photo}(photo=${cart.photo})}"
width=
"300"
height=
"200"
/></td>
<td
class=
"tdCart"
><p
th:text=
"${cart.shoesName}"
class=
"textP"
>
Convers All Star
</p></td>
<td
class=
"tdCart"
><input
type=
"number"
th:value=
"${cart.quantity}"
class=
"textP itemCount"
></input></td>
<td
class=
"tdCart"
><input
type=
"number"
min=
"0"
th:value=
"${cart.quantity}"
class=
"textP itemCount"
></input></td>
<td
class=
"tdCart"
><p
th:text=
"${cart.price}"
class=
"textP"
>
¥
10000
</p></td>
<td
class=
"tdCart"
><button
type=
"button"
class=
"itemCountChange"
>
数変更確定
</button></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