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
f7a017cb
Commit
f7a017cb
authored
Oct 21, 2020
by
keita.onoguchi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'カート編集' into 'master'
カート編集 See merge request
!64
parents
8f1819b0
5cdd3b62
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
8 deletions
+34
-8
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+13
-6
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
+1
-1
No files found.
src/main/java/com/example/api/EcsiteRestController.java
View file @
f7a017cb
...
@@ -70,7 +70,7 @@ public class EcsiteRestController {
...
@@ -70,7 +70,7 @@ public class EcsiteRestController {
//カート追加処理
//カート追加処理
@PostMapping
(
"inputCart"
)
@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
());
shoes
=
shoesService
.
findOne
(
data
.
getShoesId
());
if
(
shoes
.
getStock
()
<
data
.
getQuantity
()){
if
(
shoes
.
getStock
()
<
data
.
getQuantity
()){
...
@@ -89,10 +89,11 @@ public class EcsiteRestController {
...
@@ -89,10 +89,11 @@ public class EcsiteRestController {
//カートのアイテム数をセッションに追加
//カートのアイテム数をセッションに追加
session
.
setAttribute
(
"cartValue"
,
data
.
getQuantity
());
session
.
setAttribute
(
"cartValue"
,
data
.
getQuantity
());
//セッションがnull出ない場合
//セッションがnull出ない場合
return
cart
;
}
else
{
}
else
{
//HashMapを生成
//HashMapを生成
ArrayList
<
String
>
list
=
new
ArrayList
<
String
>
();
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
ArrayList
<
String
>
list
=
new
ArrayList
<
String
>
();
String
id
=
data
.
getShoesId
().
toString
();
String
id
=
data
.
getShoesId
().
toString
();
//生成したHashMapにセッションにもともとある情報を照会させる。
//生成したHashMapにセッションにもともとある情報を照会させる。
cart
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
cart
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
...
@@ -100,9 +101,10 @@ public class EcsiteRestController {
...
@@ -100,9 +101,10 @@ public class EcsiteRestController {
cart
.
forEach
((
key
,
value
)
->{
cart
.
forEach
((
key
,
value
)
->{
if
(
key
.
equals
(
id
)){
if
(
key
.
equals
(
id
)){
sameId
=
key
;
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
()));
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()
+
cart
.
get
(
id
).
getQuantity
()));
}
else
{
}
else
{
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
...
@@ -112,18 +114,23 @@ public class EcsiteRestController {
...
@@ -112,18 +114,23 @@ public class EcsiteRestController {
int
nowQuantity
=
(
int
)
session
.
getAttribute
(
"cartValue"
);
int
nowQuantity
=
(
int
)
session
.
getAttribute
(
"cartValue"
);
//カートのアイテム数をセッションに追加
//カートのアイテム数をセッションに追加
session
.
setAttribute
(
"cartValue"
,
nowQuantity
+
data
.
getQuantity
());
session
.
setAttribute
(
"cartValue"
,
nowQuantity
+
data
.
getQuantity
());
return
cart
;
}
}
}
}
@PostMapping
(
"editCart"
)
@PostMapping
(
"editCart"
)
public
void
editCart
(
@RequestBody
ItemData
data
,
Shoes
shoes
)
{
public
LinkedHashMap
<
String
,
Items
>
editCart
(
@RequestBody
ItemData
data
,
Shoes
shoes
)
{
System
.
out
.
println
(
data
.
getQuantity
());
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
String
id
=
data
.
getShoesId
().
toString
();
String
id
=
data
.
getShoesId
().
toString
();
//生成したHashMapにセッションにもともとある情報を照会させる。
//生成したHashMapにセッションにもともとある情報を照会させる。
cart
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
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
);
session
.
setAttribute
(
"cart"
,
cart
);
return
cart
;
}
}
@GetMapping
(
"buy"
)
@GetMapping
(
"buy"
)
...
...
src/main/resources/static/js/cart.js
View file @
f7a017cb
//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
(){
$
(
function
(){
$
(
'.js-modal-open'
).
on
(
'click'
,
function
(){
$
(
'.js-modal-open'
).
on
(
'click'
,
function
(){
...
@@ -42,7 +57,10 @@ $('.itemCountChange').on('click', function(event){
...
@@ -42,7 +57,10 @@ $('.itemCountChange').on('click', function(event){
dataType
:
"json"
,
dataType
:
"json"
,
data
:
JSON
.
stringify
(
data
)
data
:
JSON
.
stringify
(
data
)
})
})
window
.
location
.
href
=
"/limited/cart"
;
.
done
(
function
(){
window
.
location
.
href
=
"/limited/cart"
;
});
//[#modal-content]と[#modal-overlay]をフェードアウトした後に…
//[#modal-content]と[#modal-overlay]をフェードアウトした後に…
$
(
"#modal-content,#modal-overlay"
).
fadeOut
(
"slow"
,
function
(){
$
(
"#modal-content,#modal-overlay"
).
fadeOut
(
"slow"
,
function
(){
...
...
src/main/resources/static/js/list.js
View file @
f7a017cb
...
@@ -108,6 +108,7 @@ $('.cartBtn').on('click', function(event){
...
@@ -108,6 +108,7 @@ $('.cartBtn').on('click', function(event){
dataType
:
"json"
,
dataType
:
"json"
,
data
:
JSON
.
stringify
(
data
)
data
:
JSON
.
stringify
(
data
)
})
})
//[#modal-content]と[#modal-overlay]をフェードアウトした後に…
//[#modal-content]と[#modal-overlay]をフェードアウトした後に…
$
(
"#modal-content,#modal-overlay"
).
fadeOut
(
"slow"
,
function
(){
$
(
"#modal-content,#modal-overlay"
).
fadeOut
(
"slow"
,
function
(){
//[#modal-overlay]を削除する
//[#modal-overlay]を削除する
...
...
src/main/resources/templates/cart.html
View file @
f7a017cb
...
@@ -113,7 +113,7 @@
...
@@ -113,7 +113,7 @@
<td
class=
"hidden"
><input
th:text=
"${cart.shoesId}"
/></td>
<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"
><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"
><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"
><p
th:text=
"${cart.price}"
class=
"textP"
>
¥
10000
</p></td>
<td
class=
"tdCart"
><button
type=
"button"
class=
"itemCountChange"
>
数変更確定
</button></td>
<td
class=
"tdCart"
><button
type=
"button"
class=
"itemCountChange"
>
数変更確定
</button></td>
</tr>
</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