-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.js
29 lines (25 loc) · 1.03 KB
/
cart.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
import { getProductList } from './module/productList.js';
import { getCartData } from './module/cartToggleButton.js';
import { makeDOMwithProperties } from './utils/dom.js';
import { CART_COOKIE_KEY } from './constants/cart.js';
import { setPayInfo } from './module/payModule.js';
const $section = document.querySelector('.section-cart');
const $cartPayCon = document.querySelector('#cart-pay-container');
const savedCartList = getCartData();
const reloadPage = () => location.reload();
if (savedCartList.length < 1) {
const noCartDOM = makeDOMwithProperties('div', {
className: 'product-list-con',
innerText: '장바구니에 상품이 없습니다.',
});
$section.insertBefore(noCartDOM, $cartPayCon);
} else {
const $productListCon = getProductList(savedCartList, reloadPage);
$section.insertBefore($productListCon, $cartPayCon);
}
const $cartRemoveAllBtn = document.querySelector('#remove-all-button');
$cartRemoveAllBtn.addEventListener('click', () => {
localStorage.removeItem(CART_COOKIE_KEY);
reloadPage();
});
setPayInfo();