// [KR] 마이페이지 index 에서 최근 30일 주문내역을 표시하기 위해 helper 및 custom module 추가 class CustomMyOrders extends ShopbySkin.modules.MyOrders { async setup() { super.setup(); const { result: orderList } = await callShopApi('/profile/orders', 'GET', { accessTokenType: 'member', }); // [Jay] 렌탈 주문건 렌탈 데이터 추가 for (const order of orderList.items) { if (order.payType === 'RENTAL') { const orderNo = order.orderNo; const { result: orderInfo } = await callShopApi( `/profile/orders/${orderNo}`, 'GET', { accessTokenType: 'member', }, ); order.orderOptions[0].rentalInfo = orderInfo.payInfo.rentalInfo; } } this.store.setState((prev) => ({ ...prev, myOrders: orderList.items, })); } } customElements.define('custom-my-orders', CustomMyOrders); // [KR] 30일전 날짜 추출을 위한 함수 추가 const getDate30DaysAgo = () => { const date = new Date(); date.setDate(date.getDate() - 30); // 30일 전 날짜로 설정 const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); // 월은 0부터 시작하므로 +1 const day = String(date.getDate()).padStart(2, '0'); // 1자리 숫자일 때 앞에 0 추가 return `${year}-${month}-${day}`; }; (async () => { $('recent-product').velocity({ opacity: 0 }); const { actions, EventManager, pageHelper } = ShopbySkin; // [KR] 마이페이지 index 에서 최근 30일 주문내역을 표시하기 위해 helper 및 custom module 추가 const { initialize } = pageHelper.myOrdersHelper(); initialize({ pageNumber: 1, pageSize: 100, startYmd: getDate30DaysAgo(), }); ShopbySkin.Handlebars.registerHelper({ // [Jay] 총 렌탈 가격 계산을 위한 곱하기 헬퍼 추가 multiply(x, y) { return x * y; }, }); let shopbyCommonData = {}; EventManager.on('PAGE_LOAD_COMPLETED', (commonData) => { shopbyCommonData = commonData; }); const containerEl = document.querySelector( '[shopby-helper-key="my-page-helper-key"]', ); const clickEventListener = (event) => { const actionType = event.target .closest('[shopby-action]') ?.getAttribute('shopby-action'); const CLICK_EVENT_HANDLER_MAP = { LOGOUT: async () => { await actions.postSignOut(); location.href = '/'; }, GRADE_BENEFIT: () => { // [KR] 회원등급별 혜택 페이지로 이동하도록 코드 수정 location.href = '/pages/service/member-grade.html'; // [KR] 기존 팝업 소스는 주석처리 /* EventManager.fire('OPEN_LAYER_MODAL', { name: 'grade-benefit-guide', title: '등급혜택 안내', isFull: false, data: { commonData: shopbyCommonData, }, }); */ }, PRODUCT_LIKE_BTN: ({ event }) => { event?.preventDefault?.(); const btn = event.target.closest('[shopby-product-no]'); const productNo = Number(btn.getAttribute('shopby-product-no') ?? 0); actions.toggleLikeStatus({ productNo, onSuccess: (isLiked) => { if (isLiked) { btn.classList.add('is-active'); return; } btn.classList.remove('is-active'); }, }); }, INQUIRY_REGISTER: () => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'personal-inquiry-form', title: `1:1문의 등록`, modalAddClass: 'personal-inquiry-form-modal', isFull: false, data: { isModify: false, commonData: shopbyCommonData, }, onClose: ({ reason }) => { if (reason === 'DID_SUBMIT') { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', message: '게시글이 저장되었습니다.', onClose: () => { location.reload(); }, }); } }, }); }, PRODUCT_INQUIRY_REGISTER: () => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'product-inquiry-form', title: '상품문의', modalAddClass: 'product-inquiry-form-modal', isFull: false, data: { isSelectProduct: true, commonData: shopbyCommonData, }, onClose: ({ reason }) => { if (reason === 'DID_SUBMIT') { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', message: '상품문의가 등록됐습니다.', onClose: () => { location.reload(); }, }); } }, }); }, PRODUCT_REVIEW_REGISTER: () => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'product-review-form', title: '상품후기', modalAddClass: 'product-review-form-modal', isFull: false, data: { isSelectProduct: true, }, onClose: ({ reason }) => { if (reason === 'DID_SUBMIT') { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'success', message: '상품후기가 등록되었습니다.', onClose: () => { location.reload(); }, }); } }, }); }, }; CLICK_EVENT_HANDLER_MAP[actionType]?.({ event }); }; containerEl.addEventListener('click', clickEventListener); // [KR] 주문관련 event handler 추가 order-list.js 에서 복사 const openNaverPayAlertModal = (nextActionType, orderStatusType) => { const ACTION_TYPE_LABEL = { CANCEL: '취소신청', EXCHANGE: '교환신청', RETURN: '반품신청', CONFIRM_ORDER: '구매확정', }; if ( nextActionType === 'WRITE_REVIEW' && ['DELIVERY_ING', 'DELIVERY_DONE', 'BUY_CONFIRM'].includes(orderStatusType) ) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'WARNING', message: '네이버페이 주문은 네이버페이에서 구매확정 이후 후기작성이 가능합니다.', }); return; } EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'WARNING', message: `네이버페이지 주문은 네이버페이에서 ${ACTION_TYPE_LABEL[nextActionType]} 하실 수 있습니다.`, }); }; const openWithdrawClaimModal = (orderOptionNo, claimStatusLabel) => { EventManager.fire('MODAL_CONFIRM_OPEN', { noticeType: 'WARNING', message: `${claimStatusLabel} 신청을 철회하시겠습니까?`, onConfirm: async () => { const { isSuccess } = await withdrawClaimByOrderOptionNo(orderOptionNo); if (isSuccess) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', message: `${claimStatusLabel}신청 철회가 완료되었습니다.`, onClose: () => location.reload(), }); } }, }); }; const validateWithdrawClaim = ({ claimNo, claimNos, claimStatusLabel, orderOptionNo, }) => { const hasAfterClaim = claimNos .split(',') .some((no) => Number(no) > Number(claimNo)); if (!hasAfterClaim) { return true; } EventManager.fire('MODAL_CONFIRM_OPEN', { noticeType: 'WARNING', message: '철회 시 후순위 클레임의 결제/환불 금액이 변동됩니다.
클레임을 철회하시겠습니까?
', onConfirm: () => openWithdrawClaimModal(orderOptionNo, claimStatusLabel), }); return false; }; const MODULE_ACTION_HANDLER = { SEARCH_ORDERS: () => { const params = new URLSearchParams(location.search); location.href = `${location.origin}${location.pathname}?${params.toString()}`; }, CANCEL: ({ orderOptionNo, orderNo, orderOptionCount, payType, orderStatusType, orderNextActionType, }) => { const canCancelAll = orderNextActionType .split(',') .includes('CANCEL_ALL'); if (payType === 'NAVER_PAY') { openNaverPayAlertModal('CANCEL'); return; } if ( [ 'VIRTUAL_ACCOUNT', 'ESCROW_VIRTUAL_ACCOUNT', 'ESCROW_REALTIME_ACCOUNT_TRANSFER', ].includes(payType) ) { const payTypeLabel = { VIRTUAL_ACCOUNT: '가상계좌', ESCROW_VIRTUAL_ACCOUNT: '에스크로', ESCROW_REALTIME_ACCOUNT_TRANSFER: '에스크로', }; if (canCancelAll) { EventManager.fire('MODAL_CONFIRM_OPEN', { noticeType: 'WARNING', message: `${payTypeLabel[payType]} 결제 건은 전체 취소신청만 가능합니다.
모두 취소신청 하시겠습니까?
`, onConfirm: async () => { const { isSuccess } = await cancelOrder(orderNo); if (isSuccess) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', message: '전체 주문 취소가 완료되었습니다.', onClose: () => location.reload(), }); } }, }); return; } if ( orderStatusType !== 'DEPOSIT_WAIT' && [ 'ESCROW_VIRTUAL_ACCOUNT', 'ESCROW_REALTIME_ACCOUNT_TRANSFER', ].includes(payType) ) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'WARNING', message: '에스크로 결제 건은 모든 상품이 결제완료 상태에서만 취소신청이 가능합니다.
취소신청은 1:1문의를 통해 문의해주세요.
', }); return; } return; } if (canCancelAll && orderOptionCount >= 2) { // EventManager.fire('MODAL_CONFIRM_OPEN', { // hasHeader: true, // noticeType: 'WARNING', // cancelLabel: '선택 부분 취소', // confirmLabel: '즉시 전체 취소', // message: // '주문에 포함된 상품을 즉시 전체취소 하시겠습니까?
일부 상품만 부분취소 하시겠습니까?
', // onCancel: () => { // location.href = `./claim-form.html?orderOptionNo=${orderOptionNo}&claimType=CANCEL`; // }, // onConfirm: async () => { // const { isSuccess } = await cancelOrder(orderNo); // if (isSuccess) { // EventManager.fire('MODAL_ALERT_OPEN', { // noticeType: 'SUCCESS', // message: '전체 주문 취소가 완료되었습니다.', // onClose: () => location.reload(), // }); // } // }, // }); // [Jay] sb 요청으로 전체취소만 가능해야해서 취소 페이지로 이동 location.href = `./claim-form.html?orderOptionNo=${orderOptionNo}&claimType=CANCEL`; } else { location.href = `./claim-form.html?orderOptionNo=${orderOptionNo}&claimType=CANCEL`; } }, EXCHANGE: ({ orderOptionNo, deliverable, payType }) => { if (payType === 'NAVER_PAY') { openNaverPayAlertModal('EXCHANGE'); return; } if ( ['ESCROW_VIRTUAL_ACCOUNT', 'ESCROW_REALTIME_ACCOUNT_TRANSFER'].includes( payType, ) ) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'WARNING', message: '에스크로 결제 건은 교환 신청이 불가합니다.
취소/반품 후 재주문으로 처리해 주세요.
', }); return; } location.href = `./claim-form.html?orderOptionNo=${orderOptionNo}&claimType=EXCHANGE&deliverable=${deliverable}`; }, RETURN: ({ orderOptionNo, deliverable, payType }) => { if (payType === 'NAVER_PAY') { openNaverPayAlertModal('RETURN'); return; } if ( ['ESCROW_VIRTUAL_ACCOUNT', 'ESCROW_REALTIME_ACCOUNT_TRANSFER'].includes( payType, ) ) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'WARNING', message: '에스크로 결제 건은 결제업체에서 발송한 이메일에서만 반품신청이 가능합니다.
이메일 수신함을 확인해주세요.
', }); return; } location.href = `./claim-form.html?orderOptionNo=${orderOptionNo}&claimType=RETURN&deliverable=${deliverable}`; }, WITHDRAW_CANCEL: ({ orderOptionNo, claimNo, claimNos }) => { const claimStatusLabel = '취소'; if ( !validateWithdrawClaim({ claimNo, claimNos, claimStatusLabel, orderOptionNo, }) ) { return; } openWithdrawClaimModal(orderOptionNo, claimStatusLabel); }, WITHDRAW_EXCHANGE: ({ orderOptionNo, claimNo, claimNos }) => { const claimStatusLabel = '교환'; if ( !validateWithdrawClaim({ claimNo, claimNos, claimStatusLabel, orderOptionNo, }) ) { return; } openWithdrawClaimModal(orderOptionNo, claimStatusLabel); }, WITHDRAW_RETURN: ({ orderOptionNo, claimNo, claimNos }) => { const claimStatusLabel = '반품'; if ( !validateWithdrawClaim({ claimNo, claimNos, claimStatusLabel, orderOptionNo, }) ) { return; } openWithdrawClaimModal(orderOptionNo, claimStatusLabel); }, VIEW_DELIVERY: ({ deliveryUri, deliveryType }) => { if (deliveryType === 'DIRECT_DELIVERY') { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'WARNING', message: '직접배송의 경우 배송조회를 지원하지 않습니다.
판매자에게 문의해주세요.
', }); return; } window.open(deliveryUri); }, CONFIRM_ORDER: async ({ orderOptionNo, payType, orderStatusType }) => { if (payType === 'NAVER_PAY') { openNaverPayAlertModal('CONFIRM_ORDER', orderStatusType); return; } const { isSuccess } = await confirmOrder(orderOptionNo); if (isSuccess) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', message: '구매확정 처리되었습니다.', onClose: () => location.reload(), }); } }, WRITE_REVIEW: ({ payType, productNo, orderStatusType }) => { if (payType === 'NAVER_PAY') { openNaverPayAlertModal('WRITE_REVIEW', orderStatusType); return; } EventManager.fire('OPEN_LAYER_MODAL', { name: 'product-review-form', title: '상품후기', modalAddClass: 'product-review-form-modal', isFull: false, data: { productNo, isModify: false, }, onClose: ({ reason }) => { if (reason === 'DID_SUBMIT') { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'success', message: '상품후기가 등록되었습니다.', onClose: () => { location.reload(); }, }); } }, }); }, VIEW_CLAIM_DETAIL: ({ claimNo, modalTitlePrefix }) => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'claim-detail', title: `${modalTitlePrefix ?? '클레임'} 내역 상세`, isFull: false, data: { claimNo, }, }); }, }; const dateSearchModule = document.querySelector('date-search'); const dateSearchClickEventListener = ({ target }) => { const actionTarget = target.getAttribute('shopby-action'); if (!actionTarget) { return; } MODULE_ACTION_HANDLER[actionTarget](); }; dateSearchModule?.addEventListener('click', dateSearchClickEventListener); const orderProductOptionsModule = document.querySelector('custom-my-orders'); const orderProductOptionsClickEventListener = ({ target }) => { const actionTarget = target.getAttribute('shopby-action'); if (!actionTarget) { return; } const orderOptionCount = target .closest('[shopby-order-option-count]') ?.getAttribute('shopby-order-option-count'); const orderOptionNo = target .closest('[shopby-order-option-no]') ?.getAttribute('shopby-order-option-no'); const payType = target .closest('[shopby-pay-type]') ?.getAttribute('shopby-pay-type'); const orderStatusType = target .closest('[shopby-order-status]') ?.getAttribute('shopby-order-status'); const deliverable = target.getAttribute('shopby-deliverable'); const deliveryUri = target.getAttribute('shopby-delivery-uri'); const claimNo = target.getAttribute('shopby-claim-no'); const modalTitlePrefix = target.getAttribute('shopby-modal-title-prefix'); const productNo = target.getAttribute('shopby-product-no'); const orderNo = target.getAttribute('shopby-order-no'); const deliveryType = target.getAttribute('shopby-delivery-type'); const claimNos = target .closest('[shopby-claim-nos]') ?.getAttribute('shopby-claim-nos'); const orderNextActionType = target .closest('[shopby-order-next-action-type]') ?.getAttribute('shopby-order-next-action-type'); MODULE_ACTION_HANDLER[actionTarget]({ orderOptionCount, orderOptionNo, deliverable, deliveryUri, claimNo, modalTitlePrefix, productNo, orderNo, payType, orderStatusType, deliveryType, claimNos, orderNextActionType, }); }; orderProductOptionsModule.addEventListener( 'click', orderProductOptionsClickEventListener, ); $('recent-product').velocity({ opacity: 1 }, { duration: 1000 }); // [KR] 회원듭급 컬러 표시 const profileSummaryEl = document.querySelector('profile-summary'); // [KR] 검색창 모달 인기검색어 영역 updateSlot 추가 profileSummaryEl.store.attach('profile', async (state) => { const profile = state.profile; const memberGradeNo = profile.memberGradeNo; const gradeInfo = await callShopApi( `/member-grades?gradeNos=${memberGradeNo}`, ); state.profile.memberGradeInfo = gradeInfo.result[0]; profileSummaryEl.updateSlot(state, 'profile'); }); })();