cart-sidebar.blade.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <!--=====================================
  2. CART SIDEBAR PART START
  3. =======================================-->
  4. <aside class="cart-sidebar">
  5. <div class="cart-header">
  6. <div class="cart-total">
  7. <i class="fas fa-shopping-basket"></i>
  8. <span>total item (<span class="cart-item-num">0</span>)</span>
  9. </div>
  10. <button class="cart-close"><i class="icofont-close"></i></button>
  11. </div>
  12. <ul class="cart-list">
  13. </ul>
  14. <div class="cart-footer">
  15. <button class="coupon-btn">Do you have a coupon code?</button>
  16. <form class="coupon-form">
  17. <input type="text" placeholder="Enter your coupon code">
  18. <button type="submit"><span>apply</span></button>
  19. </form>
  20. <a class="cart-checkout-btn" href="{{ route('checkout.index') }}">
  21. <span class="checkout-label">결제하기</span>
  22. <span class="checkout-price">0</span>
  23. </a>
  24. </div>
  25. </aside>
  26. <!--=====================================
  27. CART SIDEBAR PART END
  28. =======================================-->
  29. @push('js')
  30. <script>
  31. $(document).ready(async function() {
  32. const response = await call_shop_cart_api()
  33. if (window.Member) {
  34. get_cart_item(response.data)
  35. }
  36. });
  37. async function call_shop_cart_api() {
  38. return await get_api_data('list-type1-page', {
  39. QueryVars: {
  40. QueryName: 'point2u::pro:shop/cart',
  41. SubSimpleFilter: "image_type = 'thumb'",
  42. IsntPagination: true
  43. },
  44. PageVars: {
  45. Limit: 10000
  46. }
  47. })
  48. }
  49. function get_cart_item(d) {
  50. let html = ''
  51. let cart_total_prc = 0
  52. if ( d.Page ) {
  53. d.Page.forEach(cart => {
  54. cart_total_prc += Number(cart['C8'])
  55. let route_url = '{{ route('item-details', ':id') }}'
  56. route_url = route_url.replace(':id', cart['C10'] ? cart['C10'] : cart['C1'])
  57. html += `
  58. <li class="cart-item" data-id="${cart['Id']}">
  59. <div class="cart-media">
  60. <a href="#"><img src="${window.env['MEDIA_URL'] + cart['C2']}" alt="product"></a>
  61. <button class="cart-delete" onclick="cart_delete(${cart['Id']})"><i class="far fa-trash-alt"></i></button>
  62. </div>
  63. <div class="cart-info-group">
  64. <div class="cart-info">
  65. <h6><a href="${route_url}">${cart['C4']}</a></h6>
  66. <p>Unit Price - ${format_decimal(cart['C6'], 0)} 원</p>
  67. </div>
  68. <div class="cart-action-group">
  69. <div class="product-action">
  70. <button type="button" class="action-minus" title="Quantity Minus"><i class="icofont-minus"></i></button>
  71. <input class="action-input" title="Quantity Number" onchange="cart_qty_update(this, ${cart['Id']})"
  72. type="text" name="quantity" min="1" value="${Number(cart['C7'])}">
  73. <button type="button" class="action-plus" title="Quantity Plus"><i class="icofont-plus"></i></button>
  74. </div>
  75. <h6><span class="cart-amt">${format_decimal(cart['C8'], 0)}</span> 원</h6>
  76. </div>
  77. </div>
  78. </li>
  79. `
  80. })
  81. } else {
  82. html = '쇼핑카트가 비어있습니다';
  83. }
  84. const cart_total_num = d.Page?.length
  85. $('.cart-sidebar .cart-item-num').text(cart_total_num)
  86. $('.cart-sidebar .checkout-price').text(format_decimal(cart_total_prc, 0))
  87. // if (cart_total_num > 0) {
  88. // const header_cart_item_num = '.header-cart .cart-item-num'
  89. // const mobile_cart_item_num = '.mobile-menu .cart-item-num'
  90. //
  91. // const val = cart_total_num > 9 ? '9+' : cart_total_num
  92. // $(header_cart_item_num).text(val)
  93. // $(header_cart_item_num).show()
  94. //
  95. // $(mobile_cart_item_num).text(val)
  96. // $(mobile_cart_item_num).show()
  97. // }
  98. $('.cart-sidebar > .cart-list').html(html)
  99. }
  100. async function cart_qty_update($this, cart_id) {
  101. const qty = Number($($this).val())
  102. if (qty < 1) {
  103. $($this).val(1)
  104. iziToast.info({ title: 'Info', message: '수량 에러' })
  105. return
  106. }
  107. const cart_pick = await get_api_data('cart-pick', {
  108. Page : [ { Id: Number(cart_id), MemberBuyerId: window.Member['MemberBuyerId'] } ]
  109. })
  110. const cart = cart_pick.data.Page[0]
  111. const cart_amt = String(Number(cart.CartPrc) * Number($($this).val()));
  112. const response = await get_api_data('cart-act', {
  113. Page : [
  114. {
  115. Id: Number(cart_id),
  116. CartPrc: cart.CartPrc,
  117. CartQty: $($this).val(),
  118. CartAmt: cart_amt,
  119. }
  120. ]
  121. })
  122. show_iziToast_msg(response.data.Page, function () {
  123. location.reload()
  124. // if (isEmpty(callback)) {
  125. // $($this).closest('.cart-item').find('.cart-amt').text(format_decimal(cart_amt, 0))
  126. // get_cart_item_prc_total()
  127. // } else {
  128. // callback()
  129. // }
  130. })
  131. }
  132. function cart_delete(cart_id) {
  133. iziToast.question({
  134. timeout: 20000,
  135. close: false,
  136. overlay: true,
  137. displayMode: 'once',
  138. id: 'question',
  139. title: $('#comfirm-delete').text(),
  140. message: $('#can-not-recover-after-delete').text(),
  141. position: 'center',
  142. buttons: [
  143. [`<button><b>${$('#delete').text()}</b></button>`, async function (instance, toast) {
  144. instance.hide({ transitionOut: 'fadeOut' }, toast, 'button');
  145. const response = await get_api_data('cart-act', {
  146. Page : [ { Id: Number(`-${cart_id}`) } ]
  147. })
  148. show_iziToast_msg(response.data.Page, function () {
  149. location.reload()
  150. // $('.cart-sidebar > .cart-list li').each(function () {
  151. // if (Number(cart_id) === $(this).data('id')) {
  152. // $(this).remove()
  153. // }
  154. // });
  155. // get_cart_item_prc_total()
  156. })
  157. }, true],
  158. [`<button>${$('#cancel').text()}</button>`, function (instance, toast) {
  159. instance.hide({ transitionOut: 'fadeOut' }, toast, 'button');
  160. }],
  161. ],
  162. });
  163. }
  164. async function get_cart_item_prc_total() {
  165. const response = await call_shop_cart_api()
  166. let result = 0
  167. if (response['data']['Page']) {
  168. result = format_decimal(
  169. response['data']['Page'].reduce((total, cart) => { return total += Number(cart['C8']) }, 0)
  170. , 0);
  171. }
  172. $('.cart-sidebar .checkout-price').text(result)}
  173. </script>
  174. @endpush