hyeonga_code

reProject_16_ 장바구니 기능 구현 수정, 재고 수량 적용 본문

Project_WEATHERWEAR

reProject_16_ 장바구니 기능 구현 수정, 재고 수량 적용

hyeonga 2024. 1. 4. 05:59
반응형

 

 

reProject_15_주문 페이지, 주문 상세 페이지 작업

2024-01-02 주문페이지로 이동 시 session이 없는 경우(로그인하지 않은 경우) , cookie 값이 없는 경우(비회원 쿠키가 생성되지 않은 경우) 로그인/비회원으로 주문 버튼이 보여지게 된다. 로그인 시 아

hyeonga493.tistory.com

 

2024.01.03

팀원들과 작업한 장바구니 기능 구현에 관한 회의를 진행했다. 

-- 다르게 작업한 부분

---- ajax 결과를 모듈화하여 DTO로 넘기도록 작업

---- 상품 상세에서 상품옵션 리스트로 Controller로 넘겨 ajax 한 번만 실행되도록 작업

---- 재고수량에 따라 추가할 수 있는 상품 수량 제한

 

-- 상품옵션을 list로 넘겨 ajax가 한 번만 처리되도록 변경

-- 재고 수량에 따라 추가할 수 있는 상품 수량 제한 기능 추가

>>> 상품 옵션을 앞단에서 list로 가져와 처리하는 작업에서 쿠키, 세션을 설정하는 부분에서 생각하는 데에 시간이 좀 걸렸다.

>>> 재고를 가져오는 것에서 어떻게 처리할 지 고민이 많았으나 현재 list로 가져와 select()함수 실행시 선택한 옵션에 대한 재고를 불러오는 것으로 처리해 두었고 재고보다 많은 수량을 선택한 경우 alert을 띄우고 최대 수량으로 설정되도록 작업했다.

>>> 추후 옵션 선택시 재고가 보여지도록 작업하고 싶은 마음이 있다.

 

1. client_productInfo.jsp 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>WEATHERWEAR</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="/w2/resources/client/client_js/client_productInfo.js"></script>
    <link rel="stylesheet" href="/w2/resources/client/client_css/client_base_style.css">
    <link rel="stylesheet" href="/w2/resources/client/client_css/client_productInfo_style.css">
</head>
<body>
    <div class="container">
        <%@ include file="/WEB-INF/views/client/base/client_header.jspf" %>
        <input type="hidden" name="proPrice" value="${ product.proPrice }">
        <input type="hidden" name="proId" value="${ product.proId }">
        <input type="hidden" name="proName" value="${ product.proName }">
        <div class="body">
            <div class="product_body">
                <input type="hidden" value="${ product.optionList }" name="optionList">
                <div class="product_info">
                    <div class="product_main_image">
                        <img class="main_image" src="${ product.imageDir }${ product.imageName }"><br>
                    </div>
                    <div class="product_info_detail">
                        <ul class="product_info_ul">
                            <li class="product_info_li productName">
                                ${ product.proName }
                            </li>
                            <li class="product_info_li productPrice">
                                <fmt:formatNumber value="${ product.proPrice }" pattern="###,### 원"/>
                            </li>
                            <li class="product_info_li">
                                <label for="opColor" class="product_info_label">색상</label>
                                <select class="select" id="opColor" onchange="select(this)">
                                    <option value="SELECT">선택</option>
                                    <c:forEach var="color" items="${ product.colorList }">
                                        <option value="${ color }">${ color }</option>
                                    </c:forEach>
                                </select>
                            </li>
                            <li class="product_info_li">
                                <label for="opSize" class="product_info_label">사이즈</label>
                                <select class="select" id="opSize" onchange="select(this)">
                                    <option value="SELECT">선택</option>
                                    <c:forEach var="size" items="${ product.sizeList }">
                                        <option value="${ size }">${ size }</option>
                                    </c:forEach>
                                </select>
                            </li>
                            <li class="product_info_optionSelect">
                                <section class="total_price">
                                    <ul class="product_form_ul">
                                        <li class="product_form_th">
                                            총 상품 금액 : 
                                        </li>
                                        <li class="product_form_td">
                                            <input type="number" name="odTotal" value="0" id="odTotal" disabled="disabled">
                                        </li>
                                    </ul>
                                </section>
                                <section id="selectOption">
                                
                                </section>
                            </li>
                            <li class="product_info_li">
                                <form id="product_add_form">
                                    <ul class="product_order_ul">
                                        <li class="product_order_li">
                                            <input class="order_btn" type="button" value="찜하기">
                                        </li>
                                        <li class="product_order_li">
                                            <input class="order_btn" type="button" value="장바구니에 담기" onclick="addCart()">
                                        </li>
                                        <li class="product_order_li">
                                            <input class="order_btn" type="button" value="바로 주문하기">
                                        </li>
                                    </ul>
                                </form>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="product_info_menu">
                    <ul class="product_info_menu_ul">
                        <li class="product_info_menu_li">
                            <a id="proDetail_btn" onclick=' moveToProductInfoMenu()'>상세 정보</a>
                        </li>
                        <li class="product_info_menu_li">
                            <a id="proReview_btn">리뷰</a>
                        </li>
                        <li class="product_info_menu_li">
                            <a id="proQna_btn">문의</a>
                        </li>
                    </ul>
                </div>
                <div class="product_detail">
                    <div class="product_detailImage">
                        <c:forEach var="im" items="${ product.detailImage }">
                            <img class="detailImage" src="${ product.imageDir }${ im }"><br>
                        </c:forEach>
                    </div>
                    <div class="product_content">
                        ${ product.proContent }
                    </div>
                </div>            
            </div>
        </div>
        <%@ include file="/WEB-INF/views/client/base/client_footer.jspf" %>
    </div>
</body>
</html>
cs

 

 

2. client_productInfo.js 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 
function getOpList(){
    let optionList = $("input[name='optionList']").val();
    let opList = [];
    
    optionList = optionList.slice(1-1);
    optionList = optionList.slice(1-1);
    
    let option = optionList.split("}, {");
    
    option.forEach(op => {
        let option = new Map();
        op = op.split(', ');
        
        for(let i=0; i<op.length; i++){
            let keyValue = op[i].split('=');
            option.set(keyValue[0], keyValue[1]);
        }
        
        opList.push(option);
    });
    return opList;
}
 
// 옵션 수량 변경
function count(num, name) {
    var cnt = parseInt($("div[name='" + name + "'] input[name='cnt" + name + "']").val());
    var stCnt = parseInt($("div[name='" + name + "'] input[name='pro_" + name + "_cnt']").val());
    var odTotal = parseInt($("input[name='odTotal']").val());
    let proPrice = parseInt($("input[name='proPrice']").val());
    
    console.log("재고 : " + stCnt);
    console.log("num : " + num);
    
    if (num == -1) {
        odTotal += proPrice;
        cnt++;
    } else if (num == -2){
        odTotal -= proPrice;
        cnt--;
    } else {
        odTotal = proPrice*parseInt(num);
        console.log("odTotal : " + odTotal);
        cnt = num;
    }
    
    if (cnt < 1) {
        cnt = 0;
        $("div[name='" + name + "']").remove();
    } else if(cnt > stCnt){
        cnt = stCnt;
        alert("재고가 부족합니다.");
    }
    
    $("div[name='" + name + "'] input[name='cnt" + name + "']").val(cnt);
    $("input[name='odTotal']").val(odTotal);
}
 
// 옵션 선택
function select(selectElement) {
    let opList = getOpList();
    
    var color = document.getElementById("opColor").value;
    //console.log(color);
    var size = document.getElementById("opSize").value;
    //console.log(size);
    var odTotal = parseInt($("input[name='odTotal']").val());
    var proName = $("input[name='proName']").val();
    var proId = $("input[name='proId']").val();
    
    if(color === "SELECT" || size === "SELECT"){
        return;
    }
    
    let stCnt = 0;
    
    opList.forEach(op => {
        
        if(op.get("opColor"== color && op.get("opSize"== size){
            stCnt = op.get("stCnt");    
            console.log("select stCnt : " + stCnt);    
        }
    
    });
    
    var name= color+size;
    
    if($("#"+name).length){
        alert("이미 선택한 옵션입니다.");
        count(1name);
    } else {
        var select = "";
        select += "<div name='" + color + size + "' id='" + color + size + "' class='selectValue'>"
                + "<span class='proName'>" + proName + "</span>&nbsp;/&nbsp;" + color + "&nbsp;/&nbsp;" + size + "&nbsp;&nbsp;&nbsp;<br>"
                + "<button type='button' class='pro_btn' onclick='count(-2,\"" + name +"\")'>-</button>"
                + "<input class='pro_btn' id='cnt" + name + "'  name='cnt" + name + "' style='width:35px; height:27px; margin-left:3px; margin-right:3px; text-align:center;' value=1 max-value=" + stCnt + " onChange='count(this.value,\"" + name +"\")'>"
                + "<button type='button' class='pro_btn' onclick='count(-1,\"" + name +"\")'>+</button>"
                + "<input type='hidden' name='opId' value='" + proId + name + "'><input type='hidden' name='pro_" + name + "_cnt' value='" + stCnt + "'>"
                + "<button id='id' name='" + name + "' class='pro_btn' onclick='deleteSelected(this)' style='flozat:right; margin-left:10px;'>X</button>"
                + "</div>";
 
        count(1name);
        $("#selectOption").append(select);
    }            
    // 초기화
    document.getElementById("opColor").value = "SELECT";
    document.getElementById("opSize").value = "SELECT";
    console.log("________max-value : " + document.getElementById("cnt" + name + "").getAttribute("max-value"));
}
 
function moveToProductInfoMenu(){
    document.querySelector('.product_info_menu').scrollIntoView();
}
 
function deleteSelected(element){
    let cnt = $(element).parent().find("input[name='cnt" + element.name + "']").val();
    for(let i=0; i<cnt; i++){
        count(2, element.name);
    }
    $(element).parent().remove();
}
 
// 장바구니에 추가
function addCart(){
    // cartVO 객체를 가지는 리스트
    let proId = $("input[name='proId']").val();
    let list = addList(proId);
    console.log(proId);
    
    $.ajax({
        url: "/w2/clientAddCart.do",
        type: "POST",
        async: true,
        data: JSON.stringify(list),
        contentType: "application/json",
        success: function(response){
            if(confirm("장바구니에 상품이 담겼습니다.\n장바구니로 이동하시겠습니까?")) {
                 location.href="clientCart.do";
             } else {
                 reload:"clientProductInfo.do?proId="+proId;
             }
        },
        error : function(error){
            alert("실패");
        }
    });
}
 
// 상품 리스트에 담기
function addList(proId){
    let list = [];
    let productCounts = document.querySelectorAll(".selectValue");
 
    productCounts.forEach(product => {
        let colorSize = product.id;
        let cart = {}; // 객체 생성
        
        cart.proId = proId;
        cart.opId = product.querySelector("input[name='opId']").value;
        cart.caCnt = product.querySelector("input[name='cnt" + colorSize + "']").value;
        
        //console.log("pro : " + cart);
        
        list.push(cart);
    });
    
    return list;
}
cs

 

 

3. ClientGetController.java 수정

    /** 상품 상세 페이지 */
    @RequestMapping("clientProductInfo.do")
    public String clientProductInfo(@RequestParam(value = "proId", required = false)String proId, Model model) {
        System.out.println("1. [ Client Post Controller ] clientProductInfo");
        
        model.addAttribute("product", productService.clientProductInfo(proId));
        return "client_productInfo";
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.w2.client.controller;
 
import java.util.HashMap;
import java.util.List;
 
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.util.WebUtils;
 
import com.w2.client.ClientService;
import com.w2.client.ClientVO;
import com.w2.client.cart.ClientCartService;
import com.w2.client.cart.ClientCartVO;
import com.w2.client.product.ClientProductService;
 
import lombok.extern.slf4j.Slf4j;
 
@Slf4j
@Controller
public class ClientGetController {
 
    @Autowired
    private ClientService clientService;
    
    @Autowired
    private ClientProductService productService;
    
    @Autowired
    private ClientCartService cartService;
    
    /** 사용자 메인페이지 */
    @RequestMapping("clientMain.do")
    public String main() {
        log.info(null);
        return "client_main";
    }
    
    /** 상품 리스트 페이지 */
    @RequestMapping("clientProductList.do")
    public String clientProductList(@RequestParam(value = "page", required = false)Integer page, 
                                @RequestParam(value="ordertype", required=falseString ordertype, 
                                @RequestParam(value="gubun", required=false)String gubun, Model model) {
        System.out.println("1. [ Client Get Controller ] productList");
        
        HashMap<String, Object> check = new HashMap<String, Object>();
        if(page == null || page == 0) {
            check.put("page"1);
        } else {
            check.put("page", (int)page);
        }
        
        check.put("table""product");
        check.put("ordertype", (String)ordertype);
        check.put("gubun", (String)gubun);
        
        
        List<HashMap<String, Object>> productList = productService.clientProductList(check, model);
        
        model.addAttribute("productList", productList);
        
        return "client_productList";
    }
    
    /** 상품 상세 페이지 */
    @RequestMapping("clientProductInfo.do")
    public String clientProductInfo(@RequestParam(value = "proId", required = false)String proId, Model model) {
        System.out.println("1. [ Client Post Controller ] clientProductInfo");
        
        model.addAttribute("product", productService.clientProductInfo(proId));
        return "client_productInfo";
    }
    
    /** 사용자 로그인 페이지 */
    @RequestMapping("clientLogin.do")
    public String login() {
        return "client_login";
    }
 
    /** 로그아웃 요청 */
    @RequestMapping("clientLogout.do")
    public String logout(HttpSession session) {
        if(session != null) {
            session.invalidate();
        }
        return "redirect:/clientMain.do";
    }
    
    /** 사용자 정보 찾기 페이지 */
    @RequestMapping("clientFindInfo.do")
    public String findInfo() {
        return "client_findInfo";
    }
 
    /** 회원가입 페이지 */
    @RequestMapping("clientSignup.do")
    public String signup() {
        return "client_signup";
    }
    
    /** 커뮤니티 페이지 */
    @RequestMapping("clientCommunity.do")
    public String community() {
        return "client_community";
    }
    
    /** 마이페이지 */
    @RequestMapping("clientMypage.do")
    public String mypage(HttpSession session, ClientVO client, Model model) {
        System.out.println("1. [ Client Get Controller ] myPage ");
        
        if(session!=null) {
            HashMap<String, Object> myinfo = clientService.clientSetMypage((String)session.getAttribute("session"));
            model.addAttribute("myinfo", myinfo);
        }
        
        return "client_mypage";
    }
    
    /** 장바구니 */
    @RequestMapping("clientCart.do")
    public String cart(HttpServletRequest request, HttpSession session, Model model, ClientCartVO cartvo) {
        System.out.println("1. [ Client Get Controller ] cart");
        
        if((String)session.getAttribute("session"== null) {
            Cookie cookie = WebUtils.getCookie(request, "clientCookie");
            if (cookie != null) {
                System.out.println("비회원인데 장바구니는 있음");
                cartvo.setCkId((String)cookie.getValue());
            }
        } else {
            System.out.println("회원 있음 : " + (String)session.getAttribute("session"));
            cartvo.setClientId((String)session.getAttribute("session"));
        }
        
        model.addAttribute("cartList", cartService.getClientCartList(cartvo));
        return "client_cart";
    }
    
    /** 상품 주문 */
    @RequestMapping("clientOrder.do")
    public String clientOrder() {
        return "client_order";
    }
    
    /** 주문 상세 */
    @RequestMapping("clientOrderInfo.do")
    public String clientOrderInfo() {
        return "client_orderInfo";
    }
}
cs

 

 

 

4. CilentProductDAO.java 클래스 작성

    // 상품 상세
    public HashMap<String, Object> clientProductInfo(String proId) {
        System.out.println("3. [ Product DAO ] clientProductInfo");
        
        HashMap<String, Object> product = sqlSessionTemplate.selectOne("ProductDAO.clientProductInfo", proId);

        List<Object> optionList = sqlSessionTemplate.selectList("ProductDAO.getOption", proId);
        
        Set<String> colorSet =  new HashSet<>();
        Set<String> sizeSet =  new HashSet<>();
        
        for(Object option : optionList) {
            @SuppressWarnings("unchecked")
            HashMap<String, String> optionMap = (HashMap<String, String>) option;
            colorSet.add((String)optionMap.get("opColor"));
            sizeSet.add((String)optionMap.get("opSize"));
        }
        
        product.put("optionList", optionList);
        product.put("colorList", new ArrayList<>(colorSet));
        product.put("sizeList", new ArrayList<>(sizeSet));
        product.put("detailImage", sqlSessionTemplate.selectList("ProductDAO.getDetailImage", proId));
        
        return product;
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.w2.client.product;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
@Repository
public class ClientProductDAO {
 
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    
    // 상품 리스트 조회
    public List<HashMap<String, Object>> clientProductList(HashMap<String, Object> check) {
        System.out.println("3. [ Product DAO ] productList");
        
        return sqlSessionTemplate.selectList("ProductDAO.clientProductList", check);
    }
 
    // 상품 개수 확인
    public int searchCount(HashMap<String, Object> check) {
        System.out.println("3. [ Product DAO ] searchCount");
        
        return sqlSessionTemplate.selectOne("ProductDAO.searchCount", check);
    }
 
    // 상품 상세
    public HashMap<String, Object> clientProductInfo(String proId) {
        System.out.println("3. [ Product DAO ] clientProductInfo");
        
        HashMap<String, Object> product = sqlSessionTemplate.selectOne("ProductDAO.clientProductInfo", proId);
 
        List<Object> optionList = sqlSessionTemplate.selectList("ProductDAO.getOption", proId);
        
        Set<String> colorSet =  new HashSet<>();
        Set<String> sizeSet =  new HashSet<>();
        
        for(Object option : optionList) {
            @SuppressWarnings("unchecked")
            HashMap<StringString> optionMap = (HashMap<StringString>) option;
            colorSet.add((String)optionMap.get("opColor"));
            sizeSet.add((String)optionMap.get("opSize"));
        }
        
        product.put("optionList", optionList);
        product.put("colorList"new ArrayList<>(colorSet));
        product.put("sizeList"new ArrayList<>(sizeSet));
        product.put("detailImage", sqlSessionTemplate.selectList("ProductDAO.getDetailImage", proId));
        
        return product;
    }
}
 
cs

 

 

 

7. client-product-mapping.xml 파일 작성

    <resultMap id="optionInfoResult" type="HashMap">
        <result property="opColor" column="opColor"/>
        <result property="opSize" column="opSize"/>
        <result property="stCnt" column="stCnt"/>
    </resultMap>
    
	<!-- 상품 옵션, 재고 조회 -->
    <select id="getOption" resultMap="optionInfoResult">
        SELECT  opColor, opSize, stCnt FROM option_info
        WHERE proId = #{proId};
    </select>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?xml version="1.0" encoding="UTF-8"?>
 
<!-- MyBatis 다운 파일 PDF 에서 붙여넣은 내용입니다. -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
                 
<mapper namespace="ProductDAO">
    
    <!-- 사용 가능 
    <sql id="미리 지정가능">지정하고 싶은 값 입력 가능</sql>
    <include refid="미리 지정가능"/>
    -->
    
    <resultMap id="optionInfoResult" type="HashMap">
        <result property="opColor" column="opColor"/>
        <result property="opSize" column="opSize"/>
        <result property="stCnt" column="stCnt"/>
    </resultMap>
    
    <!-- 상품 리스트 -->
    <select id="clientProductList" resultType="HashMap" parameterType="HashMap">
        SELECT pro.proId, pro.proName, pri.proPrice, img.imageName, img.imageDir
        FROM product pro
        LEFT JOIN product_price pri ON pro.proId = pri.proId
        LEFT JOIN product_image img ON pro.proId = img.ImageBy AND img.ImageStatus='대표'
        WHERE pro.proSell = 'Y'
        <choose>
            <when test="gubun == 'outer'">
                AND pro.proCate LIKE "11%"
            </when>
            <when test="gubun == 'top'">
                AND pro.proCate LIKE "12%"
            </when>
            <when test="gubun == 'pants'">
                AND pro.proCate LIKE "13%"
            </when>
            <when test="gubun == 'skirts'">
                AND pro.proCate LIKE "14%"
            </when>
            <when test="gubun == 'dress'">
                AND pro.proCate LIKE "15%"
            </when>
        </choose>
            ORDER BY 
        <choose>
            <when test="ordertype == 'proRegDate'">
                pro.proRegDate DESC
            </when>
            <when test="ordertype == 'proCnt'">
                pro.proCnt DESC
            </when>
            <when test="ordertype == 'proPriceH'">
                pri.proPrice DESC
            </when>
            <when test="ordertype == 'proPriceL'">
                pri.proPrice ASC
            </when>
            <when test="ordertype == 'proSell'">
                pro.proSell ASC
            </when>
            <otherwise>
                pro.proName ASC
            </otherwise>
        </choose>
        <choose>
            <when test="postStart == 1">
                LIMIT 0,20
            </when>
            <otherwise>
                LIMIT #{ postStart }, 20
            </otherwise>
        </choose>
    </select>
    
    <!-- 상품 개수 조회 -->
    <select id="searchCount" resultType="int">
        SELECT COUNT(*)
        FROM product
        JOIN product_image ON product.proId = product_image.imageBy AND product_image.imageStatus="대표"
        <choose>
            <when test="gubun == 'outer'">
                WHERE proCate LIKE "11%"
            </when>
            <when test="gubun == 'top'">
                WHERE proCate LIKE "12%"
            </when>
            <when test="gubun == 'pants'">
                WHERE proCate LIKE "13%"
            </when>
            <when test="gubun == 'skirts'">
                WHERE proCate LIKE "14%"
            </when>
            <when test="gubun == 'dress'">
                WHERE proCate LIKE "15%"
            </when>
        </choose>
    </select>
    
    <!-- 상품 상세 조회 -->
    <select id="clientProductInfo" parameterType="String" resultType="HashMap">
        SELECT pro.proId, pro.proName, pro.proContent, pro.proCate, pro.proView, pro.proLike, 
                pri.proPrice, img.imageDir, img.imageName
        FROM product pro
        LEFT JOIN product_price pri ON pro.proId = pri.proId
        LEFT JOIN product_image img ON pro.proId = img.imageBy AND img.imageStatus = "대표"
        WHERE pro.proId=#{ proId }
    </select>
    
    <!-- 상품 색상 조회 -->
    <select id="getColorList" resultType="String">
        SELECT  opColor FROM option_info
        WHERE proId = #{proId}
        GROUP BY opColor
    </select>
    
    <!-- 상품 사이즈 조회 -->
    <select id="getSizeList" resultType="String">
        SELECT  opSize FROM option_info
        WHERE proId = #{proId}
        GROUP BY opSize
    </select>
    
    <!-- 상품 상세 이미지 조회 -->
    <select id="getDetailImage" resultType="String">
        SELECT imageName FROM product_image
        WHERE imageBy = #{proId} AND imageStatus='상세'
    </select>
    
    <!-- 상품 옵션, 재고 조회 -->
    <select id="getOption" resultMap="optionInfoResult">
        SELECT  opColor, opSize, stCnt FROM option_info
        WHERE proId = #{proId};
    </select>
</mapper>
cs

 

 


>> 실행





>>> 재고 직접 입력 시 onChange 함수 실행으로 자동으로 변경

 

 

 

>>> 재고보다 많은 수량 입력시 alert 띄우고 최대 수량으로 변경

 

 

>>> 여러 상품 한번에 장바구니에 담는 경우 ajax 한번만 처리됨

 

 

 

 

>> 현재 장바구니에서 수량 변경시 DB에는 적용시키지 않은 상태다.

주문 시에 변경된 수량을 적용하면 된다고 생각했는데 페이지를 이동했다가 다시 돌아오는 경우 다시 초기화 되는 부분을 다른 팀원들은 초기화되지 않도록 작업해서 그렇게 수정하려고 한다.

반응형