Commit 1831cf9a authored by keita.onoguchi's avatar keita.onoguchi

カート画面編集途中

parent 12e311e5
......@@ -44,6 +44,7 @@ public class EcsiteRestController {
@Autowired
ShoesService shoesService;
int totalPrice;
String sameId;
//アカウント新規登録
@PostMapping("signUp")
......@@ -81,12 +82,22 @@ public class EcsiteRestController {
//セッションがnull出ない場合
}else{
//HashMapを生成
ArrayList <String> list = new ArrayList<String> ();
LinkedHashMap<String, Items> cart = new LinkedHashMap<String, Items>();
String id = data.getShoesId().toString();
//生成したHashMapにセッションにもともとある情報を照会させる。
cart = (LinkedHashMap<String, Items>) session.getAttribute("cart");
//HashMapに靴のIdをKeyとして、Valueに靴の情報を入れる。
cart.put(id, itemsService.findOne(data.getShoesId(),data.getQuantity()));
cart.forEach((key, value) ->{
if(key.equals(id)){
sameId = key;
}
});
if(sameId.equals(id)){
cart.put(id , itemsService.findOne(data.getShoesId(), data.getQuantity() + cart.get(id).getQuantity()));
}else{
cart.put(id , itemsService.findOne(data.getShoesId(),data.getQuantity()));
}
//HashMapをセッションに追加
session.setAttribute("cart", cart);
int nowQuantity = (int) session.getAttribute("cartValue");
......@@ -96,7 +107,7 @@ public class EcsiteRestController {
}
@GetMapping("buy")
public String buy(@AuthenticationPrincipal LoginUser userDetails, LinkedHashMap<String, Items> items, ArrayList <Items> cart){
public void buy(@AuthenticationPrincipal LoginUser userDetails, LinkedHashMap<String, Items> items, ArrayList <Items> cart){
items = (LinkedHashMap<String, Items>) session.getAttribute("cart");
items.forEach((key, value) -> {
cart.add(value);
......@@ -105,6 +116,6 @@ public class EcsiteRestController {
//Integer userId = user.getId();
salesLogService.update(1, cart);
session.removeAttribute("cart");
return "index";
session.removeAttribute("cartValue");
}
}
\ No newline at end of file
......@@ -16,6 +16,9 @@ $('#ok-btn').on('click',function(){
type:'GET',
url:'/limited/buy'
})
.done()
return false;
.done(function(){
$('.js-modal').fadeOut();
alert("購入が完了しました。");
window.location.href = "/limited/top";
})
});
\ No newline at end of file
......@@ -111,7 +111,7 @@
<tr class="row tr">
<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.quantity}" class="textP"></p></td>
<td class="tdCart"><input type="number" th:value="${cart.quantity}" class="textP"></input></td>
<td class="tdCart"><p th:text= "${cart.price}" class="textP">&yen;10000</p></td>
</tr>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment