(() => { const { EventManager, pageHelper, actions, modules, utils } = ShopbySkin; const myProductReviewListHelper = pageHelper.myProductReviewListHelper(); myProductReviewListHelper.initialize(); // 샵바이 모듈 커스텀 class CustomProductReviewList extends modules.ProductReviewList { // 오버라이딩 getReviewedProducts = async () => { const { searchType, keyword, pageSize } = this.props; const now = new Date(); const start = new Date(); start.setFullYear(now.getFullYear() - 1); const formatDate = (date) => date.toISOString().split('T')[0]; const { data } = await actions.fetchProfileReviewedProducts({ searchType, searchKeyword: keyword, pageNumber: this.pageNumber, pageSize, startYmd: formatDate(start), // 검색 기간 1년으로 설정 }); const newItems = data.items.map((item) => ({ ...item, starSet: utils.getStarSet({ score: item.rate, totalScore: utils.MAX_RATING_SCORE }), })); return { items: newItems, totalCount: data.totalCount }; }; // 오버라이딩 fetchProductReviewsByPagination = ({ data: { items, totalCount } }) => { const paginationInstance = new utils.Pagination({ currentPageKey: 'pageNumber', pageSizeKey: 'pageSize', totalCount, currentPage: Number(this.pageNumber), itemsPerPage: Number(this.props.pageSize), visiblePagesCount: this.props.visiblePagesCount, }); const queryParams = { pageNumber: this.pageNumber, pageSize: this.props.pageSize, searchType: this.props.searchType, keyword: this.props.keyword, }; paginationInstance.setQueryParams(queryParams); const pagination = paginationInstance.generate(); this.store.setState({ items, totalCount, pagination, isLoading: false, keyword: this.props.keyword, searchType: this.props.searchType, }); }; setQueryString = () => { const params = new URLSearchParams(location.search); params.set('keyword', this.props.keyword || ''); params.set('searchType', this.props.searchType || 'ALL'); params.set('pageNumber', String(this.pageNumber)); history.replaceState({}, '', `${location.origin}${location.pathname}?${params.toString()}`); }; // 오버라이딩 fetchReviewedProduct = async (isInitial = false) => { if (this.props.usesInfiniteScroll) { this['fetchProductReviewsByInfinity'](); // 부모 클래스 private 함수 호출 } else { const data = await this.getReviewedProducts(); // 커스텀 클래스에서 오버라이딩한 함수 호출 if (this.props.usesPagination) { this.fetchProductReviewsByPagination({ data }); } else { this['fetchProductReviewsByMoreButton']({ data, isInitial }); } this.setQueryString(); setParams(); } }; } customElements.define("custom-product-review-list", CustomProductReviewList); // 커스텀 모듈 바인딩 const moduleActionHandler = { REGISTER: (_, { productNo, reviewNo, usesAttachment }) => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'product-review-form', title: '상품 후기 등록', modalAddClass: 'product-review-form-modal', isFull: false, data: { productNo, reviewNo, usesAttachment, isSelectProduct: true, useSelectOrderProduct: true, // useSelectOrderProduct 값 가져와서, 다시보기 버튼 보이게 하기 }, onClose: ({ reason }) => { if (reason === 'DID_SUBMIT') { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'success', message: '상품후기가 등록되었습니다.', onClose: () => { location.replace(location.pathname); }, }); } }, }); }, }; const setParams = () => { const params = new URLSearchParams(window.location.search); const keyword = params.get("keyword"); const searchType= params.get("searchType"); if (!keyword && !searchType) return; const searchFieldEl = document.querySelector('search-field[shopby-module-key="product-review-list-search-field"]'); if (!searchFieldEl) return; const newState = { ...searchFieldEl.store?.getState(), keyword: keyword || '', type: searchType || 'ALL', }; searchFieldEl.store?.setState(newState); searchFieldEl.handleRender?.({ state: newState }); } document.querySelector('product-review-total-count')?.addEventListener('click', ({ target }) => { const action = target.getAttribute('shopby-action'); const productNo = target.closest('[shopby-product-no]')?.getAttribute('shopby-product-no'); const reviewNo = target.closest('[shopby-review-no]')?.getAttribute('shopby-review-no'); const usesAttachment = target.closest('[shopby-uses-attachment]')?.getAttribute('shopby-uses-attachment'); moduleActionHandler[action]?.(myProductReviewListHelper, { productNo, reviewNo, usesAttachment }); }); document.addEventListener("DOMContentLoaded", () => { const popover = document.querySelector("#review-policy"); const button = popover.previousElementSibling; if(popover && button) { button.addEventListener("click", (e) => { e.stopPropagation(); popover.classList.toggle("active"); }); const observer = new IntersectionObserver(([entry]) => { const popover = document.querySelector('#review-policy'); if (!entry.isIntersecting) { popover.classList.remove('active'); } }, { threshold: 0 }); observer.observe(button); window.addEventListener('click', (event) => { if (popover.classList.contains('active')) { if (!popover.contains(event.target)) { popover.classList.remove('active'); } } }); } }); })();