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

カート画面編集途中

parent 12e311e5
...@@ -44,6 +44,7 @@ public class EcsiteRestController { ...@@ -44,6 +44,7 @@ public class EcsiteRestController {
@Autowired @Autowired
ShoesService shoesService; ShoesService shoesService;
int totalPrice; int totalPrice;
String sameId;
//アカウント新規登録 //アカウント新規登録
@PostMapping("signUp") @PostMapping("signUp")
...@@ -81,12 +82,22 @@ public class EcsiteRestController { ...@@ -81,12 +82,22 @@ public class EcsiteRestController {
//セッションがnull出ない場合 //セッションがnull出ない場合
}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>();
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");
//HashMapに靴のIdをKeyとして、Valueに靴の情報を入れる。 //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をセッションに追加 //HashMapをセッションに追加
session.setAttribute("cart", cart); session.setAttribute("cart", cart);
int nowQuantity = (int) session.getAttribute("cartValue"); int nowQuantity = (int) session.getAttribute("cartValue");
...@@ -96,7 +107,7 @@ public class EcsiteRestController { ...@@ -96,7 +107,7 @@ public class EcsiteRestController {
} }
@GetMapping("buy") @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 = (LinkedHashMap<String, Items>) session.getAttribute("cart");
items.forEach((key, value) -> { items.forEach((key, value) -> {
cart.add(value); cart.add(value);
...@@ -105,6 +116,6 @@ public class EcsiteRestController { ...@@ -105,6 +116,6 @@ public class EcsiteRestController {
//Integer userId = user.getId(); //Integer userId = user.getId();
salesLogService.update(1, cart); salesLogService.update(1, cart);
session.removeAttribute("cart"); session.removeAttribute("cart");
return "index"; session.removeAttribute("cartValue");
} }
} }
\ No newline at end of file
...@@ -16,6 +16,9 @@ $('#ok-btn').on('click',function(){ ...@@ -16,6 +16,9 @@ $('#ok-btn').on('click',function(){
type:'GET', type:'GET',
url:'/limited/buy' url:'/limited/buy'
}) })
.done() .done(function(){
return false; $('.js-modal').fadeOut();
alert("購入が完了しました。");
window.location.href = "/limited/top";
})
}); });
\ No newline at end of file
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
<tr class="row tr"> <tr class="row tr">
<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"><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> <td class="tdCart"><p th:text= "${cart.price}" class="textP">&yen;10000</p></td>
</tr> </tr>
</div> </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