옵션 1 1. 컬러랩_우유톤업크림_50 ML
"; } popupTemplate += " "; $frame.html(popupTemplate); } function renderTotalPrice($frame, items) { var totalPrice = 0; var totalNum = 0; $.each(items, function (index, item) { totalPrice += parseInt(item.totalPrice); totalNum += parseInt(item.itemCount); }); $('#selectedItemCount').text(totalNum); $frame.children(".nuNumber").text($.number(totalPrice)); // 미미 포인트 적립 표시 if( ('#memePoint').length > 0 ) { if( totalPrice > 0 ){ $('#memePointInfo').hide(); $('#memePoint').text(calculateMemePoint(totalPrice)); $('#memePointResult').show(); } else { $('#memePointInfo').show(); $('#memePointResult').hide(); $('#memePoint').text('0'); } } } // 미미 포인트 계산 function calculateMemePoint(totalPrice){ var point = 0; try{ point = Math.ceil((totalPrice * memePointRate) / 100); } catch(ex){ point = 0; } return $.number(point); } function addCartLayer(element){ var isFirstCart = true; var isAdditional = $(element).hasClass('selectAdditionalItem') ? true : false; var item = {}; item.itemId = $(element).val(); if ($(element).val() == 0) { return false; } else { // 일치하는 아이템 있을 때 (기존 객체 내 수량증가) $.each(cartItems, function (index, cartItem) { if (item.itemId === cartItem.itemId && isFirstCart === true) { cartItem.itemCount++; if (cartItem.itemCount > cartItem.limit) { cartItem.itemCount = cartItem.limit; } cartItem.totalPrice = cartItem.price * cartItem.itemCount; isFirstCart = false; } }); // 일치하는 아이템 없을 때 (신규 객체 push) if (isFirstCart === true) { item.title = $(element).find('option:selected').text(); item.price = parseInt($(element).find('option:selected').data('price')); item.totalPrice = item.price; item.limit = parseInt($(element).find('option:selected').data('limit')); item.min = parseInt($(element).find('option:selected').data('min')); item.itemCount = item.min; item.type = 'shop'; item.additional = (isAdditional) ? true : false; cartItems.push(item); } } renderCartItem($(".cartItem"), cartItems, isAdditional); renderTotalPrice($itemPrice, cartItems); renderCartPopup($(".itemShow"), cartItems); } function resetCombinationSub(combinationIndex){ nextItems = combinationItems; if(combinationIndex > 0){ nextItems = findCombinationItems($('.combinationMain').val()); } $('.'+selectedDiv+' .combinationSub').each(function(){ var obj = $(this); if(obj.data('combination-index') > combinationIndex){ obj.children('option:not(:first)').remove(); var option1 = obj.data('selectric'); option1.refresh(); }else if(obj.data('combination-index') < combinationIndex){ nextItems = (Number(obj.val()) === 0)? nextItems : findCombinationItems(obj.val()); }else{ selectedLabel = obj.children("option:first").text(); } }); } // 조합형 옵션 선택시 하위 데이터 찾기 // optionValues : '여자', '빨강', ... function findCombinationItems(optionValue){ var findItem = $.map(nextItems.optionValues, function(item, index){ if(item.value === optionValue){ return item.child } }); return (findItem.length > 0)? findItem[0] : {}; } function makeCombinationSub(combinationIndex){ var isFirst = true; $('.'+selectedDiv+' .combinationSub').each(function(index) { if (index === 0 && isFirst === true) { $('.combinationOptionList').show(); isFirst = false; } var obj = $(this); if (obj.data('combination-index') == combinationIndex) { var childOption = ''; $.each(nextItems.optionValues, function(index1, item) { var calculatePrice = (item.minPrice > 0)? item.minPrice - selectedMainItemPrice : 0; var optionValue = (depthSize == item.depth)? item.itemList[0] : item.value; childOption +=''; }); obj.append(childOption); obj.selectric('refresh'); obj.selectric('open'); requiredItemFilled(combinationIndex-1); return false; } }); return nextItems.optionValues.child; } $('.dealSelect').selectric({ maxHeight: 100000, labelBuilder: function(currItem) { return currItem.text; }, optionsItemBuilder: function(itemData) { var priceLabel = (itemData.data.price > 0)? '' + $.number(itemData.data.price) + '원' : ''; priceLabel = (!itemData.data.soldout || itemData.data.soldout === 2)? priceLabel : '품절'; return '' + itemData.text + '' + priceLabel; }, onBeforeOpen: function() { $(this).prop('selectedIndex', 0).selectric('refresh'); $('.selectric-items li[data-index="0"]').css('display', 'none'); }, onOpen: function() { $optionScroll.addClass('selectOpen'); getOptionsHeight(); }, onClose: function(element) { addCartLayer(element); $(this).prop('selectedIndex', 0).selectric('refresh'); $optionScroll.removeClass('selectOpen'); getOptionsHeight(); } }); $('.selectAdditionalItem').selectric({ optionsItemBuilder: function(itemData) { var priceLabel = (itemData.data.price > 0)? '' + $.number(itemData.data.price) + '원' : ''; priceLabel = (!itemData.data.soldout || itemData.data.soldout === 2)? priceLabel : '품절'; return '' + itemData.text + '' + priceLabel; }, onOpen:function() { $optionScroll.addClass('selectOpen'); getOptionsHeight(); }, onClose: function(element) { addCartLayer(element); $(this).prop('selectedIndex', 0).selectric('refresh'); $optionScroll.removeClass('selectOpen'); getOptionsHeight(); } }); $('.combinationMain').selectric({ onOpen: function(element){ selectedDiv = $(element).parent().parent().parent().parent().attr('class'); //$(this).selectric('refresh'); //$('.combinationOptionList').show(); $('.combinationOptionList').hide(); $optionScroll.addClass('selectOpen').addClass('selectOpenCombination'); getOptionsHeight(); // 하위옵션 선택상태 초기화 resetCombinationSub(0); }, onClose: function(element) { if(Number($(element).val()) === 0){ $('.combinationOptionList').hide(); return true; } // 하위옵션 선택상태 초기화 resetCombinationSub(0); // 1depth에서 선택한 금액 기록 - 최종단계에서 금액 차이를 비교하기 위함 selectedMainItemPrice = Number($(element).children("option:selected").data('price')); // 다음 옵션에 보여질 데이터 찾기 nextItems = findCombinationItems($(element).val()); // 하위 옵션 보이기 makeCombinationSub(1); requiredItemFilled('main'); getOptionsHeight(); return false; }, labelBuilder: function(currItem) { return (currItem.value == 0) ? currItem.text : '기본 ' + currItem.value + ''; } }); $('.combinationSub').selectric({ onBeforeOpen: function() { $('.selectric-items li[data-index="0"]').css('display', 'none'); }, onOpen: function(element) { var currentIndex = $(element).data('combination-index'); // 하위옵션 선택상태 초기화 resetCombinationSub(currentIndex); var prevValue = null; $('.combinationSub').each(function() { var obj = $(this); if (obj.data('combination-index') == (currentIndex-1)) { prevValue = obj.val(); return false; } }); if(currentIndex > 1 && Number(prevValue) === 0){ // alert('상위 옵션을 먼저 선택해주세요.'); $('.combinationSub').each(function() { if ($(this).data('combination-index') == currentIndex-1) { $(this).selectric('open'); return false; } }); $(element).selectric('close'); return false; } getOptionsHeight(); return true; }, onClose: function(element) { if(Number($(element).val()) === 0){ return true; } var currentIndex = $(element).data('combination-index'); var nextIndex = Number(currentIndex) + 1; // 다음 옵션에 보여질 데이터 찾기 nextItems = findCombinationItems($(element).val()); if(nextIndex < depthSize){ // 하위 옵션 보이기 makeCombinationSub(nextIndex); }else{ // 선택한 상품 표시 $('.combinationOptionList').hide(); $optionScroll.removeClass('selectOpen').removeClass('selectOpenCombination'); addCartLayer(element); getOptionsHeight(); } return false; }, optionsItemBuilder: function(itemData, element, index) { var priceLabel = (itemData.data.calculateprice > 0)? '+' + $.number(itemData.data.calculateprice) + '원' : ''; return '' + itemData.text + '' + priceLabel; }, labelBuilder: function(currItem) { return (currItem.value == 0) ? currItem.text : selectedLabel+' ' + currItem.value + ''; } }); // 즉시구매 처리 var submitCheckout = false; $('.infoBtnCell .btnMeme').on('click', function (e) { e.preventDefault(); if(submitCheckout){ return false; } if(cartItems.length <= 0){ alert('구매할 상품을 선택하세요.'); return false; } var searchKeyword = getUrlParameter('q'); var st = getUrlParameter('st'); var sct = getUrlParameter('sct'); submitCheckout = true; var cart = []; $.each(cartItems, function(index, item) { cart.push({'itemId': item.itemId, 'itemCount': item.itemCount, 'itemTitle': item.title, 'price': item.price}); }); try { analytics.track('Button Clicked', { category: 'Product Page', label: 'Checkout Right Away Button', s_keywords: searchKeyword }); } catch (e) {} checkOut(cart, function (err, result) { submitCheckout = false; if (err) { alert(err); return false; } var loginChk = ''; if (!loginChk && !!result.type && result.type == 'temp') { location.href='/login?returnUrl='+escape('/bridge/checkout'); return false; } if(!result.cid){ alert('일시적인 오류입니다. 고객센터에 문의해 주세요'); return false; } location.href ='https://order.memebox.com/order/'+result.cid+'?q='+encodeURI(searchKeyword) + '&st=' + st + '&sct=' + sct; }); return false; }); // 장바구니 넣기 처리 var submitCart = false; $('.infoBtnCell .btnGray').on('click', function () { if(submitCart || $(this).hasClass('btnDisabled')){ return false; } submitCart = true; var cart = []; $.each(cartItems, function(index, item) { cart.push({'itemId': item.itemId, 'itemCount': item.itemCount, 'itemTitle': item.title, 'price': item.price}); }); addCart(cart, function (err, result) { submitCart = false; if (err) { alert(err); return false; } if(result.cartTotalCount >= 0){ if(!!$('.cart-block-number').length) { $(".cart-block-number").html(result.cartTotalCount); } else { $('.cart-block-icon').append('' + result.cartTotalCount + ''); } } if(confirm('장바구니에 상품이 담겼습니다. 장바구니로 이동하시겠습니까?')){ setTimeout(function(){ location.href='https://order.memebox.com/cart'; },100); } }); return false; }); // 즉시구매 처리 function checkOut(cartItems, callback){ if (cartItems.length == 0) { return callback('옵션을 선택해주세요.'); } var cartObject = { carts: cartItems }; var apiUrlp = '/ajax/checkout'; $.ajax({ type: 'post', url: apiUrlp, data: cartObject, cache: false }).done(function (jqXHR) { callback(null, jqXHR.data); /* for (var i = 0; i < cartItems.length; i++) { // Segment Analytics: Add To Cart analytics.track('Product Added', { id: '36472', // Product ID sku: cartItems[i].itemId, // SKU is Variant ID name: '[컬러랩] 우유 톤업 크림', // Product Name brand: '컬러랩', // Product Brand variant: cartItems[i].itemTitle, // Variant Name price: cartItems[i].price, // Variant Price quantity: cartItems[i].itemCount, // Variant Quantity currency: 'KRW', // Currency: Korean Won list: '[object Object]', // Product Referring List label: '[컬러랩] 우유 톤업 크림' // Which product was added to cart }); } */ }).fail(function (jqXHR) { // 해당 오류 메세지 노출 var jqXHRTmp = JSON.parse(jqXHR.responseText); callback(jqXHRTmp.msg); }).always(function () { }); } // 수량 증가 $(document).on('click', '.btnQty', function (e) { var $this = $(this); var thisId = $this.closest('.selectedItem').data('id'); var thisIdMin = $this.closest('.selectedItem').find('.inputQty').data('min'); var thisIdLimit = $this.closest('.selectedItem').find('.inputQty').data('limit'); var amount = $this.closest('.selectedItem').find('.inputQty'); var isAdditional = $this.closest('.selectedItem').data('additional'); $.each(cartItems, function(index, cartItem) { if (thisId == cartItem.itemId) { if ($this.hasClass('btnQtyUp')) { if (cartItem.itemCount >= thisIdLimit) { alert('해당 옵션의 최대 구매 수량은 ' + thisIdLimit + '개입니다.'); cartItem.itemCount = thisIdLimit; } else { cartItem.itemCount++; } } else { if (cartItem.itemCount < thisIdMin) { alert('해당 옵션의 최소 구매 수량은 ' + thisIdMin + '개입니다.'); cartItem.itemCount = thisIdMin; } else { if (cartItem.itemCount <= 1) { return false; } else { cartItem.itemCount--; } } } amount = cartItem.itemCount; cartItem.totalPrice = cartItem.price * cartItem.itemCount; } }); renderCartItem($(".cartItem"), cartItems, isAdditional); renderTotalPrice($itemPrice, cartItems); renderCartPopup($(".itemShow"), cartItems); return false; }); $(document).on('keydown', '.inputQty', function() { var temp = $(this).val(); var isAdditional = $(this).closest('.selectedItem').data('additional'); $(this).on('change keyup paste', function() { var regexp = /[^[0-9]/gi; if (regexp.test($(this).val())) { alert('숫자만 입력 가능합니다.'); $(this).val(temp); $(this).focus(); return false; } else { var $this = $(this); var thisId = $this.closest('.selectedItem').data('id'); var thisIdMin = $this.closest('.selectedItem').find('.inputQty').data('min'); var thisIdLimit = $this.closest('.selectedItem').find('.inputQty').data('limit'); $.each(cartItems, function(index, cartItem) { if (thisId == cartItem.itemId) { if($this.val() > thisIdLimit){ alert('해당 옵션의 최대 구매 수량은 '+ thisIdLimit +'개입니다.'); cartItem.itemCount = thisIdLimit; }else if($this.val() < thisIdMin){ alert('해당 옵션의 최소 구매 수량은 ' + thisIdMin + '개입니다.'); cartItem.itemCount = thisIdMin; }else{ cartItem.itemCount = $this.val(); } cartItem.totalPrice = cartItem.price * cartItem.itemCount; } }); renderCartItem($(".cartItem"), cartItems, isAdditional); renderTotalPrice($itemPrice, cartItems); renderCartPopup($(".itemShow"), cartItems); } }); }); // 선택한 아이템 삭제처리 $(document).on('click', '.btnItemDelete', function () { var $this = $(this); var thisId = $this.closest('.selectedItem').data('id'); var cartItemsRemoval = []; var isAdditional = $this.closest('.selectedItem').data('additional'); var mainItemCount = 0; var additionalItemCount = 0; $.each(cartItems, function(index, cartItem) { if(thisId == cartItem.itemId) { cartItemsRemoval.push(index); }else if(cartItem.additional === false){ mainItemCount++; }else if(cartItem.additional === true){ additionalItemCount++; } }); if(additionalItemCount > 0 && mainItemCount === 0){ alert('추가상품만 구매할 수 없습니다.'); return false; } for (var i = 0; i < cartItemsRemoval.length; i++) { cartItems.splice(cartItemsRemoval[i], 1); } renderCartItem($(".cartItem"), cartItems, isAdditional); renderTotalPrice($itemPrice, cartItems); renderCartPopup($(".itemShow"), cartItems); if ($('.additionalItemList .selectedItem').length < 1) { $('.additionalItemList').remove(); } if (cartItems.length < 1) { $('.availableMaxNum').remove(); $('.selectedItemListBlock').remove(); $optionScroll.removeClass('showPrice'); requiredItemFilled(); //$itemPrice.hide(); } return false; }); // Option Scroll /* var optionScroll = new IScroll('.dealOrderInner', { useTransform: false, bounce: false, mouseWheel: true, click: true, scrollbars: true, fadeScrollbars: true });*/ });