<main>
<section class="content">
<th:block th:include="/product/side.html"/>
<div class="cart">
<h1>장바구니</h1>
<form id="order-form" action="/product/order">
<div>
<div class="cart_header">
<input type="checkbox" id="check-all">
<label for="check-all">전체선택(0)</label>
<button type="button">선택삭제</button>
</div>
<div th:each="cart : ${cartDTOList}" class="cart_content" th:attr="data-prod-no=${cart.product.prodNo}" data-point="1">
<div>
<label>
<input type="checkbox" name="cartNo" th:value="${cart.cartNo}"/>
[[${cart.product.seller.company}]]
</label>
</div>
<div>
<div class="cart_product">
<div>
<img th:src="${cart.product.productImage.sNameList}" alt="상품 이미지">
</div>
<div>
<p class="vendor-name">[[${cart.product.seller.company}]]</p>
<p>
<span>[[${cart.product.prodBrand}]] </span><br>
[[${cart.product.prodName}]]
</p>
<p class="price_delivery" th:attr="data-delivery-fee=${cart.product.prodDeliveryFee}">
<span th:if="${cart.product.prodDeliveryFee == 0}">무료배송</span>
<span th:if="${cart.product.prodDeliveryFee != 0}">
배송비: [[${#numbers.formatInteger(cart.product.prodDeliveryFee, 3, 'COMMA')}]]원
</span>
</p>
<span class="arrival-date">도착예정</span>
</div>
</div>
<div class="options-container">
<div th:if="${not #strings.isEmpty(cart.opt1Cont)}">
<p th:text="${cart.opt1 + ': ' + cart.opt1Cont}"></p>
</div>
<div th:if="${not #strings.isEmpty(cart.opt2Cont)}">
<p th:text="${cart.opt2 + ': ' + cart.opt2Cont}"></p>
</div>
<div th:if="${not #strings.isEmpty(cart.opt3Cont)}">
<p th:text="${cart.opt3 + ': ' + cart.opt3Cont}"></p>
</div>
<div th:if="${not #strings.isEmpty(cart.opt4Cont)}">
<p th:text="${cart.opt4 + ': ' + cart.opt4Cont}"></p>
</div>
<div th:if="${not #strings.isEmpty(cart.opt5Cont)}">
<p th:text="${cart.opt5 + ': ' + cart.opt5Cont}"></p>
</div>
<div th:if="${not #strings.isEmpty(cart.opt6Cont)}">
<p th:text="${cart.opt6 + ': ' + cart.opt6Cont}"></p>
</div>
</div>
<div class="quantity-box">
<button class="btn-minus" type="button">-</button>
<span class="quantity">[[${cart.cartProdCount}]]</span>
<button class="btn-plus" type="button">+</button>
</div>
<div class="cart_price">
<p class="price_original"
th:attr="data-unit=${cart.product.prodPrice}">
[[${#numbers.formatInteger(cart.product.prodPrice * cart.cartProdCount, 3, 'COMMA')}]]원
</p>
<p class="price_total"
th:attr="data-unit=${(cart.product.prodPrice * (100 - cart.product.prodDiscount) / 100)}">
[[${#numbers.formatInteger((cart.product.prodPrice * (100 - cart.product.prodDiscount) / 100) * cart.cartProdCount, 3, 'COMMA')}]]원
</p>
<p>혜택변경</p>
</div>
</div>
</div>
</div>
<div class="cart_summary">
<p>결제예정금액</p>
<form>
<table>
<tr><th>상품수</th><td id="summary-count">0</td></tr>
<tr><th>상품금액</th><td id="summary-amount">0</td></tr>
<tr><th>할인금액</th><td id="summary-discount">0</td></tr>
<tr><th>배송비</th><td id="summary-shipping">0</td></tr>
<tr class="total"><th>총</th><td id="summary-total">0</td></tr>
<tr><td colspan="2"><button type="submit" id="order-button">주문하기</button></td></tr>
</table>
</form>
</div>
</form>
</div>
</section>
</main>
기술 설명
레이아웃 구조
<main>→<section class="content">로 메인 콘텐츠 영역 구분.<th:block th:include="/product/side.html"/>: 좌측 사이드바(카테고리 메뉴 등) 공통 템플릿 포함.장바구니 제목
<h1>장바구니</h1>
- 페이지 최상단에 “장바구니” 문구 표시.
장바구니 폼 (
<form id="order-form" action="/product/order">)
id="order-form": 주문하기 버튼 클릭 시 사용할 JavaScript 제어 대상.action="/product/order": 선택된 장바구니 아이템을 주문 페이지로 전송.전체 선택 및 삭제 영역
<div class="cart_header"> <input type="checkbox" id="check-all"> <label for="check-all">전체선택(0)</label> <button type="button">선택삭제</button> </div>
<input type="checkbox" id="check-all">: 모든 상품을 한 번에 선택/해제하는 체크박스.<label for="check-all">전체선택(0)</label>: 선택된 항목 개수를 표시(JavaScript에서 동적으로 업데이트).<button type="button">선택삭제</button>: 선택된 체크박스에 해당하는 장바구니 항목 삭제 기능 버튼.장바구니 항목 반복 (
th:each="cart : ${cartDTOList}")<div th:each="cart : ${cartDTOList}" class="cart_content" th:attr="data-prod-no=${cart.product.prodNo}" data-point="1"> ... </div>
cartDTOList의 각cart객체를 순회하여.cart_content블록 생성.
th:attr="data-prod-no=${cart.product.prodNo}":data-prod-no속성에 상품 번호를 바인딩해 스크립트에서 참조 가능.
data-point="1": 고정값으로 설정, JavaScript 계산 시 활용.상품 선택 체크박스 및 판매자명
<label> <input type="checkbox" name="cartNo" th:value="${cart.cartNo}"/> [[${cart.product.seller.company}]] </label>
name="cartNo",th:value="${cart.cartNo}": 체크박스를 선택하면cartNo파라미터로 서버 전송.[[${cart.product.seller.company}]]: 판매자 회사명 텍스트로 출력.상품 정보 영역 (
.cart_product)<div class="cart_product"> <div> <img th:src="${cart.product.productImage.sNameList}" alt="상품 이미지"> </div> <div> <p class="vendor-name">[[${cart.product.seller.company}]]</p> <p> <span>[[${cart.product.prodBrand}]] </span><br> [[${cart.product.prodName}]] </p> <p class="price_delivery" th:attr="data-delivery-fee=${cart.product.prodDeliveryFee}"> <span th:if="${cart.product.prodDeliveryFee == 0}">무료배송</span> <span th:if="${cart.product.prodDeliveryFee != 0}"> 배송비: [[${#numbers.formatInteger(cart.product.prodDeliveryFee, 3, 'COMMA')}]]원 </span> </p> <span class="arrival-date">도착예정</span> </div> </div>
<img th:src="${cart.product.productImage.sNameList}" alt="상품 이미지">: 상품 이미지 URL 바인딩.<p class="vendor-name">[[${cart.product.seller.company}]]</p>: 판매자명 출력.- 브랜드명 및 상품명:
[[${cart.product.prodBrand}]]와[[${cart.product.prodName}]]로 표시.- 배송비 정보:
th:attr="data-delivery-fee=${cart.product.prodDeliveryFee}":data-delivery-fee속성에 배송비 저장.- 조건부 출력:
prodDeliveryFee == 0일 때 “무료배송”, 아니면 콤마 형식으로 금액 출력(예: “3,000원”).<span class="arrival-date">도착예정</span>: 예상 도착 날짜를 JavaScript로 업데이트하거나 정적 텍스트로 표시.옵션 정보 (
.options-container)<div class="options-container"> <div th:if="${not #strings.isEmpty(cart.opt1Cont)}"> <p th:text="${cart.opt1 + ': ' + cart.opt1Cont}"></p> </div> <!-- opt2Cont ~ opt6Cont 동일 구조 --> </div>
th:if="${not #strings.isEmpty(cart.optXCont)}": 옵션 값이 비어 있지 않을 때만 해당<p>태그 렌더링.- 옵션명 + 값:
cart.optX + ': ' + cart.optXCont형식으로 출력.수량 조절 박스 (
.quantity-box)<div class="quantity-box"> <button class="btn-minus" type="button">-</button> <span class="quantity">[[${cart.cartProdCount}]]</span> <button class="btn-plus" type="button">+</button> </div>
[[${cart.cartProdCount}]]: 현재 장바구니 수량 출력.- “-” 버튼(
.btn-minus), “+” 버튼(.btn-plus): JavaScript로 클릭 시 수량 감소/증가 처리.가격 정보 (
.cart_price)<div class="cart_price"> <p class="price_original" th:attr="data-unit=${cart.product.prodPrice}"> [[${#numbers.formatInteger(cart.product.prodPrice * cart.cartProdCount, 3, 'COMMA')}]]원 </p> <p class="price_total" th:attr="data-unit=${(cart.product.prodPrice * (100 - cart.product.prodDiscount) / 100)}"> [[${#numbers.formatInteger((cart.product.prodPrice * (100 - cart.product.prodDiscount) / 100) * cart.cartProdCount, 3, 'COMMA')}]]원 </p> <p>혜택변경</p> </div>
price_original:
th:attr="data-unit=${cart.product.prodPrice}": 원가 단가를data-unit속성에 저장(스크립트 참조용).th:text="${#numbers.formatInteger(cart.product.prodPrice * cart.cartProdCount, 3, 'COMMA')}": 원가 × 수량을 콤마 형식으로 표시(예: “12,000원”).price_total:
(cart.product.prodPrice * (100 - cart.product.prodDiscount) / 100): 할인율 적용 단가 계산.th:attr="data-unit=…": 할인 단가 저장.th:text="${#numbers.formatInteger(…)}: 할인 단가 × 수량을 콤마 형식으로 표시(예: “10,800원”).<p>혜택변경</p>: 프로모션이나 쿠폰 적용 버튼 등 향후 기능 확장용 안내 텍스트.결제 예정 금액 요약 (
.cart_summary)<div class="cart_summary"> <p>결제예정금액</p> <form> <table> <tr><th>상품수</th><td id="summary-count">0</td></tr> <tr><th>상품금액</th><td id="summary-amount">0</td></tr> <tr><th>할인금액</th><td id="summary-discount">0</td></tr> <tr><th>배송비</th><td id="summary-shipping">0</td></tr> <tr class="total"><th>총</th><td id="summary-total">0</td></tr> <tr><td colspan="2"><button type="submit" id="order-button">주문하기</button></td></tr> </table> </form> </div>
id="summary-count",summary-amount,summary-discount,summary-shipping,summary-total":
- JavaScript에서 장바구니 항목 수량, 금액, 할인, 배송비, 총합을 실시간 계산하여 해당
<td>에 삽입.<button type="submit" id="order-button">주문하기</button>:
- 요약된 결제 금액을 확인한 후 폼을 제출하여
/product/order로 이동.