// 주문옵션 UI 컨트롤 스크립트 // encoding = UTF-8 ; var temporary_basket = (function (jQuery) { function _class( options ){ var self = this; // 기본 옵션 this.defaults = { IS_MOBILE_MODE : false, MODE : "GOOD", // GOOD:상품, MODIFY:장바구니, MATRIX:선택구매, WISH:위시리스트 THIS_VAR_NAME : "__TB", // 로그인 여부(0,1) LOGIN_STATE : "", // 현재 로그인한 회원등급(0=비회원) USER_GROUP : 0, // 상품seq GOOD_SEQ : "", // 카테고리 GOOD_CATE : null, // 가격선택옵션 노출방식 (단일선택 0, 분리선택 1) GOOD_OPT_SEL_TYPE : 0, // 가격 타입(단일0, 가격선택 1, 필수선택 2, 추가구성 4, 입력형 8) (옵션이 중첩일 경우 합으로 계산 ex: 가격 + 필수 = 3) PRICE_MODE : "0", // 가격갯수(0개는 판매불가능) PRICE_COUNT : 0, // 기준가격 STANDARD_PRICE : 0, // 아무런 옵션이 없는 단순형 가격인가? IS_SIMPLE_PRICE : 0, // true=1, false=0 // 미리선택된 가격정보 DEFAULT_PRICE_DATA : null, DEFAULT_PRICE_OPTION_DATA : null, // 장바구니번호 CART_SEQ : -1, // form이름 // 임시바구니form이름 ORDER_BASKET_FORM_NAME : "dataForm", // 상품변경버튼 ID REPLACE_PRICE_ID : "__replace_price_button", // 품절여부 IS_SOLDOUT : 0, // 가격 및 옵션 선택 레이어ID SELECTION_ID : "PRODUCT_PRICE_SELECTION_SECTION", // 가격 및 옵션을 선택한 레이어ID SELECTED_ID : "PRODUCT_PRICE_SELECTED_SECTION", // 선택한 가격 및 옵션을 담을 ul의 id SELECTED_LIST_ID : "PRODUCT_PRICE_SELECTED_LIST", // 선택한 추가옵션 SELECTED_ADD_OPTION_LIST_ID : "PRODUCT_PRICE_OPTION_SECTION", // 총합가격 패널 id TOTAL_PRICE_PANEL_ID : "dat_total_price_panel", // 총합가격 텍스트 id TOTAL_PRICE_TEXT_ID : "dat_total_price_text", // 옵션가격 select1 name OPTION_PRICE_NAME1 : "good_option_grid_x", // 옵션가격 select2 name OPTION_PRICE_NAME2 : "good_option_grid_y", // 옵션가격 항목 이름1,2 OPTION_PRICE_VALUES : { 'xtitle': '항목1', 'ytitle': '항목2' }, // 통화(앞) CURRENCY_FRONT : "₩", // 통화(뒤) CURRENCY_REAR : "원", // 통화 소수점 자릿수 DECIMAL_CURRENCY : 0, // 0, 1, 2 (지정 자릿수 이하는 round반올림 처리) // 가격정보 배열 PRODUCT_PRICE_ARRAY : [], // 필수선택옵션 포맷 OPTION_REQUIRE_NAME_FORMAT : "good_option_require", // 입력형 포맷 OPTION_INPUT_NAME_FORMAT : "good_input_option", // 추가구성 옵션 포맷 OPTION_ADDITION_NAME_FORMAT : "good_option_single", // 이미지 경로 IMAGE_PATH : "", // 팝업창 여부 IS_POPUP : false, // 재입고신청 여부 RESTOCK_TYPE : 0, // 재고표시 여부 SHOW_STOCKCOUNT : false, // 버튼들ID BUTTON_SOLDOUT_ID : "btn_soldout", BUTTON_ADDCART_ID : "btn_addcart", BUTTON_GOOD_BUY_ID : "btn_good_buy", BUTTON_WISHLIST_ID : "btn_wishlist", BUTTON_APPLY_MODIFY : "btn_apply_modify", BUTTON_APPLY_CANCEL : "btn_apply_cancel", BUTTON_CLOSE : "btn_close", BUTTON_CLOSE_HANDLER: null, // 가격대체문구 GOOD_PRICE_SUB_KEYWORD_USE : 0 }; // 옵션 merge this.options = jQuery.extend({}, this.defaults, options); // 주요 form jQuery객체 this.$basket_obj = null; this.$virtual_form_obj = null; // 담기 처리 this.mode = 'CART'; // PRODUCT, CART, WISH, BUY this.basketDel = 'N'; this.cart_seq = -1; // 추가된 가격 데이터들 (주문옵션 - 가격선택 옵션, 필수선택 옵션, 입력형 옵션) this.PRICE_DATA = []; // 추가된 추가옵션 데이터들 (추가옵션 - 추가구성옵션) this.PRICE_ADDITION_DATA = []; // 옵션가격에서 ajax로 받아온 가격정보 저장변수 this.stock_option_info = null; // 단순가격 구매불가능 예외처리용 변수 this.SIMPLE_PRICE_GRANT_ERROR = false; // 초기화 메소드 this.init = function (){ // form객체 얻기 this.$basket_obj = jQuery("form[name='"+this.options.ORDER_BASKET_FORM_NAME+"']"); this.options.CURRENCY_FRONT = jQuery.trim(this.options.CURRENCY_FRONT); this.options.CURRENCY_REAR = jQuery.trim(this.options.CURRENCY_REAR); this.$basket_obj.submit(function () { var total_price = self.get_total_price(); if ( total_price < 0 ){ alert("선택하신 상품 금액이 0원보다 작습니다."); return false; } if ( self.PRICE_DATA.length > 0 ){ for ( var i=0; i0||event.keyCode>0||event.which>0)){ if (window.event && (window.event.charCode>0||window.event.keyCode>0||window.event.which>0)) event = window.event; } var key = event.charCode>0 ? event.charCode : ( event.keyCode>0 ? event.keyCode : event.which); /* 방향키(37,39) 백스페이스(8) DEL(46) INSERT(45) CTRL+A : 스킵 */ if ( key == 17 || key == 37 || key == 39 || key == 8 || key == 45 || key == 46 || key == 35 || key == 36 || key == 9 ) { return ; } var STRING_LEN = 50; var WORD_COUNT = 0; var TMP ; var LEN = this.value.length ; for ( i=0 ; i 4 ) { WORD_COUNT += 2 ; } else { WORD_COUNT++ ; } } if ( WORD_COUNT > STRING_LEN ) { alert ( STRING_LEN + "byte 까지 입력할 수 있습니다.") ; this.value = MSG_BUFFER ; this.focus() ; return ; } else { MSG_BUFFER = this.value ; } }); // 옵션 세팅 : STR if (this.options.GOOD_PRICE_SUB_KEYWORD_USE == 1) { jQuery("select[id^='" +this.options.OPTION_PRICE_NAME1+ "'],select[id^='" +this.options.OPTION_PRICE_NAME2+ "']", this.$basket_obj).each(function () { this.disabled = true; }); jQuery("select[id^='" +this.options.OPTION_REQUIRE_NAME_FORMAT+ "']", this.$basket_obj).each(function () { this.disabled = true; }); jQuery("select[id^='"+this.options.OPTION_ADDITION_NAME_FORMAT+"']", this.$basket_obj).each(function () { this.disabled = true; }); jQuery("input[id^='"+this.options.OPTION_INPUT_NAME_FORMAT+"']", this.$basket_obj).each(function () { this.disabled = true; }); } else { // 가격선택옵션 jQuery("select[id^='" +this.options.OPTION_PRICE_NAME1+ "'],select[id^='" +this.options.OPTION_PRICE_NAME2+ "']", this.$basket_obj).change(function () { self.applyRequireOptionSet('required', this); }); // 필수선택옵션 jQuery("select[id^='" +this.options.OPTION_REQUIRE_NAME_FORMAT+ "']", this.$basket_obj).change(function () { self.applyRequireOptionSet('required', this); }); // 추가옵션 jQuery("select[id^='"+this.options.OPTION_ADDITION_NAME_FORMAT+"']", this.$basket_obj).change(function () { self.applyRequireOptionSet('addition', this); }); } // 옵션 세팅 : END // 상품변경(장바구니수정용)버튼 클릭이벤트 매핑 jQuery("#"+this.options.REPLACE_PRICE_ID).click(function (event) { event.preventDefault ? event.preventDefault() : event.returnValue = false; event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true; if ( self.options.IS_SOLDOUT==1 ){ alert("품절상품(재고부족)입니다."); return; } self.grabData(true); }); // 툴팁 함수가 있다면 상품변경버튼에 툴팁기능 활성화 if ( typeof(markShowEx)=='function' && typeof(markHideEx)=='function' ){ jQuery("#"+this.options.REPLACE_PRICE_ID+" img").mouseenter(function () { markShowEx(this, "BOTTOM"); }).mouseleave(function () { markHideEx(this); }); } // 기본가격이나 옵션별관리 가격이면 옵션가격 할인 설정변경 if ( this.options.PRICE_MODE == "1" || this.options.PRICE_MODE == "3" ){ var pd = this.options.PRODUCT_PRICE_ARRAY.price_list && this.options.PRODUCT_PRICE_ARRAY.price_list[0] ? this.options.PRODUCT_PRICE_ARRAY.price_list[0].price_data : null; pd = pd || jQuery("input[name='_dat_price']", this.$basket_obj).val(); if ( pd ){ pd = pd.split("|"); this.change_addition_option_price_text( pd[14]=="2" ); } } // 모든 가격 비공개 상태이면 주문옵션UI를 모두 숨긴다. if ( this.options.PRICE_COUNT == 0 ){ jQuery("#"+this.options.SELECTION_ID, this.$basket_obj).hide(); jQuery("#"+this.options.SELECTED_ID, this.$basket_obj).hide(); jQuery("#"+this.options.TOTAL_PRICE_PANEL_ID, this.$basket_obj).hide(); return; } // 단순형 가격이면 자동으로 가격 선택해준다. if ( this.options.IS_SIMPLE_PRICE == 1 ){ jQuery("#"+this.options.SELECTION_ID, this.$basket_obj).hide(); jQuery("#"+this.options.TOTAL_PRICE_PANEL_ID, this.$basket_obj).hide(); if ( self.options.IS_SOLDOUT==0 ){ // 디폴트 상품가격정보가 있다면 단순가격 자동그리기를 실행하지 않는다. if ( (this.options.DEFAULT_PRICE_DATA==null || this.options.DEFAULT_PRICE_DATA.length==0) && (this.options.DEFAULT_PRICE_OPTION_DATA==null || this.options.DEFAULT_PRICE_OPTION_DATA.length==0) ){ this.grabData(null, true/*자동실행에의한수집*/); } }else{ jQuery("#"+this.options.SELECTED_ID, this.$basket_obj).hide(); } }else{ // 처음엔 상단영역만 표시한다. jQuery("#"+this.options.SELECTION_ID, this.$basket_obj).show(); jQuery("#"+this.options.SELECTED_ID, this.$basket_obj).hide(); jQuery("#"+this.options.TOTAL_PRICE_PANEL_ID, this.$basket_obj).hide(); } // 디폴트 상품가격정보가 있다면 하단영역을 자동으로 그려준다. if ( this.options.DEFAULT_PRICE_DATA && this.options.DEFAULT_PRICE_DATA.length > 0 ){ for ( var i=0; i 0 ){ // 추가옵션 추가하기 this.add_price_option_data(this.options.DEFAULT_PRICE_OPTION_DATA); // 추가옵션 그리기 this.redrawAdditionOption(); } // 디폴트 입력옵션정보가 있다면 input에 값을 넣어준다. if ( this.options.DEFAULT_PRICE_OPTION_DATA && this.options.DEFAULT_PRICE_OPTION_DATA.input_option && this.options.DEFAULT_PRICE_OPTION_DATA.input_option.length > 0 ){ if ( this.options.DEFAULT_PRICE_OPTION_DATA.input_option.length == 1){ // 1개일경우 jQuery('#'+this.options.OPTION_INPUT_NAME_FORMAT).val(this.options.DEFAULT_PRICE_OPTION_DATA.input_option[0].value); }else{ // do nothing jQuery('input[id^="'+this.options.OPTION_INPUT_NAME_FORMAT+'"]').each(function(index){ try{ jQuery(this).val(this.options.DEFAULT_PRICE_OPTION_DATA.input_option[index].value); }catch(e){ } }); } } }; // 추가분 this.viewPrice = function () { // 가격 비공개 상태 if ( self.options.PRICE_COUNT == 0 ){ if ( self.options.LOGIN_STATE == "1" ){ alert("죄송합니다. 본 상품에 대한 구매 권한이 없습니다.\n\n회원등급을 확인해 주세요"); }else{ alert("죄송합니다. 본 상품에 대한 구매 권한이 없습니다.\n\n회원이시면 로그인 후 재시도 부탁드립니다."); } return false; } if ( self.options.IS_SOLDOUT==1 ){ alert("품절상품(재고부족)입니다."); return false; } self.grabData(); } // 선택한 주문옵션 정보 수집 메소드 this.grabData = function () { var _currentData = {}; var price_id = 0; var left_stock = -1; var option_saled = false; var replace_selection = arguments[0]; // replace_selection 추가 대신 교채여부 변수 true|null var is_initialize_execution = arguments[1]; // 단순가격일경우, 로딩시 자동으로 실행되는경우 true|null //가격선택 옵션 수집 if (( this.options.PRICE_MODE & 1 ) == 1 ){ var opt_price1_value = jQuery("select[name='"+this.options.OPTION_PRICE_NAME1+"'] option:selected", this.$basket_obj).val(); if ( opt_price1_value == '' ){ alert("가격을 선택해주십시오."); jQuery("select[name='"+this.options.OPTION_PRICE_NAME1+"']", this.$basket_obj).focus(); return; } var opt_price2_value = jQuery("select[name='"+this.options.OPTION_PRICE_NAME2+"'] option:selected", this.$basket_obj).val(); // 옵션개수1개 또는 단일선택 옵션인 경우 if (opt_price2_value == undefined) { var submit_index = opt_price1_value.split(";"); _currentData.good_opt_type = self.options.PRICE_MODE; _currentData.good_seq = self.options.GOOD_SEQ; _currentData._dat_price = submit_index[0] + "|" + submit_index[3]; _currentData.price_name = self.options.OPTION_PRICE_VALUES.xtitle + ":" + submit_index[1]; if (self.options.OPTION_PRICE_VALUES.ytitle != '') { _currentData.price_name += " / "+ self.options.OPTION_PRICE_VALUES.ytitle + ":" + submit_index[2]; } _currentData.price = submit_index[3]; //price_id = parseInt(_currentData._dat_price); price_id = parseInt(submit_index[0]); left_stock = parseInt(submit_index[4]); _currentData.stock_count = left_stock; _currentData.stock_count_min = submit_index[5]; _currentData.order_min = parseInt( submit_index[6]); _currentData.order_max = parseInt(submit_index[7]); } // 옵션개수 2개+분리선택 옵션인 경우 else { if ( this.stock_option_info == null ){ alert("가격을 선택해주십시오."); jQuery("select[name='"+this.options.OPTION_PRICE_NAME2+"']", this.$basket_obj).focus(); return; } var tmp_opt_price2 = opt_price2_value.split(";"); var opt_price2_index = tmp_opt_price2[0]; var opt_price2_value = tmp_opt_price2[1]; if ( this.stock_option_info[opt_price2_index] == null ){ alert("가격을 선택해주십시오."); jQuery("select[name='"+this.options.OPTION_PRICE_NAME2+"']", this.$basket_obj).focus(); return; } if ( this.stock_option_info[opt_price2_index].check_level>0 && this.stock_option_info[opt_price2_index].check_level!=this.options.USER_GROUP ){ // 가격 비공개 상태 if ( self.options.LOGIN_STATE == "1" ){ alert("죄송합니다. 본 상품에 대한 구매 권한이 없습니다.\n\n회원등급을 확인해 주세요"); }else{ alert("죄송합니다. 본 상품에 대한 구매 권한이 없습니다.\n\n회원이시면 로그인 후 재시도 부탁드립니다."); } return; } var submit_index = this.stock_option_info[opt_price2_index].submit_index.split(";"); _currentData.good_opt_type = self.options.PRICE_MODE; _currentData._dat_price = submit_index[0] + "|" + submit_index[2]; _currentData.good_seq = self.options.GOOD_SEQ; _currentData.price_name = self.options.OPTION_PRICE_VALUES.xtitle + ":" + jQuery("select[name='"+this.options.OPTION_PRICE_NAME1+"'] option:selected", this.$basket_obj).text() + " / " + self.options.OPTION_PRICE_VALUES.ytitle + ":" + opt_price2_value; _currentData.price = parseFloat(this.stock_option_info[opt_price2_index].sale_price); price_id = parseInt(submit_index[0]); left_stock = parseInt(this.stock_option_info[opt_price2_index].stock_count); _currentData.stock_count = left_stock; _currentData.stock_count_min = parseInt(this.stock_option_info[opt_price2_index].stock_count_min); _currentData.order_min = parseInt(this.stock_option_info[opt_price2_index].order_min); _currentData.order_max = parseInt(this.stock_option_info[opt_price2_index].order_max); } if ( left_stock>0 && _currentData.order_max>left_stock ){ _currentData.order_max = left_stock; // 남은 재고량이 최고구매수량보다 적으면, 최고구매수량에 재고량을 넣어준다. } } else { //기본 가격 정보 수집 _currentData._dat_price = jQuery("input[name='_dat_price']", this.$basket_obj).val(); var _dat_price_ar = _currentData._dat_price.split("|"); if ( _dat_price_ar[0]!="" && typeof(this.options.PRODUCT_PRICE_ARRAY.price_list[0])=='object' ){ if ( this.options.PRODUCT_PRICE_ARRAY.price_list[0].check_level > 0 && this.options.PRODUCT_PRICE_ARRAY.price_list[0].check_level!=this.options.USER_GROUP ){ var msg = ""; // 가격 비공개 상태 if ( self.options.LOGIN_STATE == "1" ){ msg = "죄송합니다. 본 상품에 대한 구매 권한이 없습니다.\n\n회원등급을 확인해 주세요"; }else{ msg = "죄송합니다. 본 상품에 대한 구매 권한이 없습니다.\n\n회원이시면 로그인 후 재시도 부탁드립니다."; } // 자동실행일 경우 alert이 아닌 메시지박스에 내용을 출력한다. if ( is_initialize_execution ){ self.SIMPLE_PRICE_GRANT_ERROR = true; jQuery("#"+this.options.SELECTED_ID, this.$basket_obj).hide(); }else{ alert(msg); } return; } }else{ alert("가격 정보에 오류가 있습니다. 관리자에 문의해주시기바랍니다.1"); return; } _currentData.good_opt_type = self.options.PRICE_MODE; _currentData.price = self.options.STANDARD_PRICE; _currentData.good_seq = self.options.GOOD_SEQ; left_stock = parseInt(_dat_price_ar[4]); _currentData.stock_count = left_stock; _currentData.order_min = parseInt(_dat_price_ar[6]); _currentData.order_max = parseInt(_dat_price_ar[7]); if ( left_stock>0 && _currentData.order_max>left_stock ){ _currentData.order_max = left_stock; // 남은 재고량이 최고구매수량보다 적으면, 최고구매수량에 재고량을 넣어준다. } if ( this.options.SHOW_STOCKCOUNT && left_stock > 0 ){ _currentData.price_name = "기본상품 (재고:"+left_stock+"개)"; }else if ( this.options.SHOW_STOCKCOUNT && left_stock < 0 ){ _currentData.price_name = "기본상품 (재고무관)"; }else{ _currentData.price_name = ''; } option_saled = _dat_price_ar[14]=="2"; } if (( this.options.PRICE_MODE & 2 ) == 2 ){ // 필수선택옵션 정보 수집 if ( !this.check_require_option() ) return; _currentData.require_option = []; jQuery("select[name^='"+this.options.OPTION_REQUIRE_NAME_FORMAT+"'] option:selected", this.$basket_obj).each(function(idx){ var require_option_index_ptn = new RegExp("option_require\\[([0-9]+)\\]"); var require_option_index = require_option_index_ptn.exec(jQuery(this).parent('select').get(0).name); require_option_index = require_option_index[1]; var values = jQuery(this).val().split(";"); if (values[1] != undefined) { _currentData.require_option.push({ name : self.options.PRODUCT_PRICE_ARRAY.multiple_options_names[require_option_index], val_seq : values[0], value : values[1], sort : require_option_index }); } }); } // 수량 _currentData.count = _currentData.order_min > 1 ? _currentData.order_min : 1; if ( replace_selection === true ){ this.clear_price_data(); } // 동일선택 상품 확인 var index_of_exists_same_price_data = -1; for ( var i=0; i 0) { self.add_price_data_count( i, 'addition_option', 0, 1 ); } else { alert('같은 종류의 무료 옵션 상품은 하나만 추가할 수 있습니다.'); } break; } } if ( index_of_exists_same_price_data == -1){ this.add_price_option_data(_currentAdditionOptionData); } // 추가옵션 그리기 this.redrawAdditionOption(); } }; // 주문옵션 정보 추가 메소드 (PRICE_DATA 생성하는 부분) this.add_price_data = function (price_data) { var idx = this.PRICE_DATA.length; var item = {}; item.id = idx; item._dat_price = price_data._dat_price; item.good_opt_type = price_data.good_opt_type item.good_seq = price_data.good_seq; item.price = price_data.price; item.price_name = price_data.price_name; item.count = parseInt(price_data.count) || 1; item.stock_count = price_data.stock_count; item.order_min = parseInt(price_data.order_min); item.order_max = parseInt(price_data.order_max); item.require_option = price_data.require_option; //item.input_option = price_data.input_option; this.PRICE_DATA.push(item); }; // 추가옵션 정보 추가 메소드 this.add_price_option_data = function (price_option_data) { var item = {}; var price = []; for ( var i=0; i 0) { for ( var i=0; i"; } } } else { jQuery("#"+this.options.SELECTED_ID, this.$basket_obj).hide(); // 기본상품 가격이 없을 경우 합계금액을 사라지게 함. if (this.PRICE_DATA.length == 0) { jQuery("#"+this.options.TOTAL_PRICE_PANEL_ID, this.$basket_obj).hide(); } //buff = "
  • 구입하실 상품을 추가해주세요.
  • "; buff = ""; } var option = jQuery("#"+this.options.SELECTED_ADD_OPTION_LIST_ID, this.$basket_obj).html(buff); // 가격이 0원인 추가옵션 상품 수량 변경 제한 jQuery(option).find('._oo_dat_addition_option_price_zero') .find('input[name^="_oo_dat_addition_option_price_count"]').prop('disabled', true).addClass('input_design').end() .find('a[id^="_oo_dat_addition_option_price_count"]').hide().end() // 모바일 .find('button[id^="_oo_dat_addition_option_price_count"]').css('visibility', 'hidden').end(); this.__event_addition_mapping(); this.place_total_price(); }; // 선택한 주문옵션 정보 다시 그리기 메소드 this.redraw = function () { // ul안에 있는 li들 초기화.. event들도 초기화되는지는 모르겠다;; jQuery("#"+this.options.SELECTED_LIST_ID, this.$basket_obj).empty(); var buff = ""; if ( self.PRICE_DATA.length > 0 ){ jQuery("#"+this.options.SELECTED_ID, this.$basket_obj).show(); jQuery("#"+this.options.TOTAL_PRICE_PANEL_ID, this.$basket_obj).show(); for ( var i=0; i"; } }else{ jQuery("#"+this.options.SELECTED_ID, this.$basket_obj).hide(); jQuery("#"+this.options.TOTAL_PRICE_PANEL_ID, this.$basket_obj).hide(); buff = "
  • 구입하실 상품을 추가해주세요.
  • "; } jQuery("#"+this.options.SELECTED_LIST_ID, this.$basket_obj).html(buff); this.__event_mapping(); this.place_total_price(); }; // 선택한 주문옵션 정보 Text 형태로 구성 this.makeText = function () { var buff = ""; var non_priced_option_text = ""; var require_option_text = ""; var input_option_data = $v($id('good_input_option')); if ( self.PRICE_DATA.length > 0 ){ for ( var i=0; i0 ){ for ( var j=0; j"; } } if ( self.PRICE_ADDITION_DATA.length > 0 ){ for ( var i=0; i"; } } if ( input_option_data != "" ){ buff += "
  • " + jQuery('#good_input_option_name').html() + ":" + input_option_data + "
  • "; } return buff; }; // 총합계금액 표시 메소드 this.place_total_price = function () { var total_price = this.get_total_price(); var price_text = ""; if ( typeof total_price == "number" ){ price_text = this.options.CURRENCY_FRONT + this.comma(total_price) + this.options.CURRENCY_REAR; }else{ price_text = "상품 가격을 선택해주세요."; } jQuery("#"+this.options.TOTAL_PRICE_TEXT_ID).text(price_text); /* 선택한 옵션들 초기화(역순으로 처리한다) */ // 추가구성 옵션 초기화 jQuery("select[name^='" +this.options.OPTION_ADDITION_NAME_FORMAT+ "']", this.$basket_obj).each(function () { jQuery("option:first", this).prop("selected", true); }); // 필수선택옵션 초기화 jQuery("select[name^='" +this.options.OPTION_REQUIRE_NAME_FORMAT+ "']", this.$basket_obj).each(function () { jQuery("option:first", this).prop("selected", true); }); // 주문옵션 초기화 jQuery("select[name='" +this.options.OPTION_PRICE_NAME2+ "'] option:gt(0)", this.$basket_obj).remove(); jQuery("select[name='" +this.options.OPTION_PRICE_NAME1+ "'] option:eq(0)", this.$basket_obj).prop("selected", true); }; // 총합계 금액 반환 메소드 this.get_total_price = function () { var total_price = 0.0; var total_count = 0; var price_text = ""; if ( this.PRICE_DATA.length > 0 ){ for ( var i=0; i 0 ){ for ( var i=0; i 0) { var price_and_count_addition = this.get_price_of(this.PRICE_ADDITION_DATA[price_data_index]); option_price = parseFloat(price_and_count_addition["price"]); } } else { // item_name == 'product' if (this.PRICE_DATA.length > 0) { var price_and_count = this.get_price_of(this.PRICE_DATA[price_data_index]); price = parseFloat(price_and_count["price"]); } } if ( price < 0 || option_price < 0){ jQuery("#_oo_dat_warn_message_"+price_data_index).show(); }else{ jQuery("#_oo_dat_warn_message_"+price_data_index).hide(); } }; // 가격정보에 -금액이 포함되어있는지 확인(iPay에서는 -금액을 지원하지 않는다) this.has_minus_price = function () { var temp = null; for ( var i=0; i0 ){ var price = 0; if ( saled ){ price = parseInt(vals[3]); }else{ price = parseInt(vals[2]); } if ( price > 0 ){ price = self.options.CURRENCY_FRONT+"+"+self.comma(price)+self.options.CURRENCY_REAR; }else{ price = self.options.CURRENCY_FRONT+self.comma(price)+self.options.CURRENCY_REAR; } this.text = vals[4]+" ("+price+" 추가)"; } }); }; // 새로 만들어진 그려진 컨트롤요소에 각종 이벤트 연결 this.__event_mapping = function () { for ( var idx=0; idx0?"(최대구매수량제한:"+self.PRICE_DATA[price_data_index].order_max+"개)":"")); this.value = self.PRICE_DATA[price_data_index].count; return; }else{ switch ( stock_status ) { case "SOLDOUT": alert("선택하신 상품은 품절입니다."); this.value = self.PRICE_DATA[price_data_index].count; return;break; case "INPUTTED_ALL": alert("선택하신 상품의 수량을 더 올릴 수 없습니다."); this.value = self.PRICE_DATA[price_data_index].count; return;break; case "OVERS_ORDER_COUNT": alert("선택하신 상품의 수량을 더 올릴 수 없습니다.(최대구매수량제한:"+self.PRICE_DATA[price_data_index].order_max+"개)"); this.value = self.PRICE_DATA[price_data_index].count; return;break; case "SHORTS_ORDER_COUNT": alert("선택하신 상품의 수량을 내릴 수 없습니다.(최소구매수량제한:"+self.PRICE_DATA[price_data_index].order_min+"개)"); this.value = self.PRICE_DATA[price_data_index].count; return;break; case "OK": // do nothing } } self.PRICE_DATA[price_data_index].count = parseInt(this.value); self.place_once_price(price_data_index, 'product', 0); self.place_total_price(); self.warn_wrong_price("product", price_data_index); /* 최소구매수량이 5, 재고8 남은 상품을 구매할때, 옵션A포함 3개+옵션B포함2개 형태로 구매할수가 없다. 상품상세페이지의 스크립트에서는 처리 가능하나, 쇼핑카트클래스에서 처리 불가능하다. 상품상세 스크립트에서는 여러개를 한꺼번에 처리하지만, 쇼핑카트클래스는 한 레코드 단위로만 처리하기 때문에 장바구니에 담겨진(담겨질)것까지 수량을 확인할 수 없다. */ }); // 기본상품 수량up버튼 매핑 jQuery("#_oo_dat_main_price_count_up_"+idx, this.$basket_obj).click(function (event) { event.preventDefault ? event.preventDefault() : event.returnValue = false; event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true; var price_data_index_ptn = new RegExp("_oo_dat_main_price_count_up_([0-9]+)"); var price_data_index = price_data_index_ptn.exec(this.id); price_data_index = price_data_index[1]; var $count_obj = jQuery("input[name='_oo_dat_main_price_count["+price_data_index+"]']", this.$basket_obj); var left_stock = parseInt(self.PRICE_DATA[price_data_index].stock_count); var stock_status = self.check_stock_count(price_data_index, 1); if ( typeof stock_status === "number" ){ // 추가 가능한 갯수를 반환했다면 최대구매수량을 초과한것이다. alert("선택하신 상품의 수량을 더 올릴 수 없습니다."+(self.PRICE_DATA[price_data_index].order_max>0?"(최대구매수량제한:"+self.PRICE_DATA[price_data_index].order_max+"개)":"")); return; }else{ switch ( stock_status ) { case "SOLDOUT": alert("선택하신 상품은 품절입니다."); return;break; case "INPUTTED_ALL": alert("선택하신 상품의 수량을 더 올릴 수 없습니다."); return;break; case "OVERS_ORDER_COUNT": alert("선택하신 상품의 수량을 더 올릴 수 없습니다.(최대구매수량제한:"+self.PRICE_DATA[price_data_index].order_max+"개)"); return;break; case "SHORTS_ORDER_COUNT": alert("선택하신 상품의 수량을 내릴 수 없습니다.(최소구매수량제한:"+self.PRICE_DATA[price_data_index].order_min+"개)"); return;break; case "OK": // do nothing } } self.add_price_data_count( price_data_index, 'product', 0, 1 ); $count_obj.val(self.get_price_data_count( price_data_index, 'product', 0 )); jQuery("#_oo_dat_main_price_count_text_"+price_data_index).html( self.get_price_data_count( price_data_index, 'product', 0 ) ); self.place_once_price(price_data_index, 'product', 0); self.place_total_price(); self.warn_wrong_price("product", price_data_index); return; }); // 기본상품 수량down버튼 매핑 jQuery("#_oo_dat_main_price_count_down_"+idx, this.$basket_obj).click(function (event) { event.preventDefault ? event.preventDefault() : event.returnValue = false; event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true; var price_data_index_ptn = new RegExp("_oo_dat_main_price_count_down_([0-9]+)"); var price_data_index = price_data_index_ptn.exec(this.id); price_data_index = price_data_index[1]; var $count_obj = jQuery("input[name='_oo_dat_main_price_count["+price_data_index+"]']", this.$basket_obj); var left_stock = self.PRICE_DATA[price_data_index].stock_count; var stock_status = self.check_stock_count(price_data_index, -1); if ( typeof stock_status === "number" ){ // 추가 가능한 갯수를 반환했다면 최대구매수량을 초과한것이다. alert("선택하신 상품의 수량을 더 올릴 수 없습니다.(최대구매수량제한:"+self.PRICE_DATA[price_data_index].order_max+"개)"); return; }else{ switch ( stock_status ) { case "SOLDOUT": alert("선택하신 상품은 품절입니다."); return;break; case "INPUTTED_ALL": alert("선택하신 상품의 수량을 더 올릴 수 없습니다."); return;break; case "OVERS_ORDER_COUNT": alert("선택하신 상품의 수량을 더 올릴 수 없습니다.(최대구매수량제한:"+self.PRICE_DATA[price_data_index].order_max+"개)"); return;break; case "SHORTS_ORDER_COUNT": alert("선택하신 상품의 수량을 내릴 수 없습니다.(최소구매수량제한:"+self.PRICE_DATA[price_data_index].order_min+"개)"); return;break; case "OK": // do nothing } } self.add_price_data_count( price_data_index, 'product', 0, -1 ); $count_obj.val(self.get_price_data_count( price_data_index, 'product', 0 )); jQuery("#_oo_dat_main_price_count_text_"+price_data_index).html( self.get_price_data_count( price_data_index, 'product', 0 ) ); self.place_once_price(price_data_index, 'product', 0); self.place_total_price(); self.warn_wrong_price("product", price_data_index); return; }); // 단순가격형이라면 기본상품 삭제버튼을 보여주면 안된다. if ( this.options.IS_SIMPLE_PRICE == 1 ){ jQuery("#_oo_dat_delete_button_"+idx, this.$basket_obj).hide(); }else{ // 기본상품 삭제버튼 매핑 jQuery("#_oo_dat_delete_button_"+idx, this.$basket_obj).click(function (event) { event.preventDefault ? event.preventDefault() : event.returnValue = false; event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true; var price_data_index_ptn = new RegExp("_oo_dat_delete_button_([0-9]+)"); var price_data_index = price_data_index_ptn.exec(this.id); price_data_index = price_data_index[1]; self.remove_price_data( price_data_index ); self.redraw(); if ( self.PRICE_DATA.length == 0 ){ self.remove_add_option_price_data('all'); self.redrawAdditionOption(); } return; }); } self.warn_wrong_price("product", idx); } }; this.__event_addition_mapping = function () { for (var idx = 0, max = self.PRICE_ADDITION_DATA.length; idx < max; idx++) { // 추가구성 수량 input 매핑 jQuery("input[name^='_oo_dat_addition_option_price_count_"+idx+"']", this.$basket_obj) .change(function(){ var price_data_index_ptn = new RegExp("_oo_dat_addition_option_price_count_([0-9]+)"); var price_data_indexes = price_data_index_ptn.exec(this.name); var price_data_index = price_data_indexes[1]; var index = price_data_indexes[2]; if ( self.PRICE_ADDITION_DATA[price_data_index] ){ var cnt = parseInt(this.value); cnt = isNaN(cnt) ? 1 : cnt; cnt = cnt < 1 ? 1 : cnt; this.value = cnt; self.PRICE_ADDITION_DATA[price_data_index].count = cnt; self.place_once_price(price_data_index, 'addition_option', index); self.place_total_price(); self.warn_wrong_price("addition_option", price_data_index); }else{ alert('PRICE_DATA 오류#1'); } }); // 추가구성 수량up버튼 매핑 jQuery("*[id='_oo_dat_addition_option_price_count_up_"+idx+"']", this.$basket_obj).click(function (event) { event.preventDefault ? event.preventDefault() : event.returnValue = false; event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true; var price_data_index_ptn = new RegExp("_oo_dat_addition_option_price_count_up_([0-9]+)"); var price_data_indexes = price_data_index_ptn.exec(this.id); var price_data_index = price_data_indexes[1]; self.add_price_data_count( price_data_index, 'addition_option', price_data_index, 1 ); jQuery("input[name='_oo_dat_addition_option_price_count_"+price_data_index+"']", this.$basket_obj).val(self.get_price_data_count( price_data_index, 'addition_option', price_data_index )); jQuery("#_oo_dat_addition_option_price_count_text_"+price_data_index+"", this.$basket_obj).html(self.get_price_data_count( price_data_index, 'addition_option', price_data_index )); self.place_once_price(price_data_index, 'addition_option', price_data_index); self.place_total_price(); self.warn_wrong_price("addition_option", price_data_index); return; }); // 추가구성 수량down버튼 매핑 jQuery("*[id='_oo_dat_addition_option_price_count_down_"+idx+"']", this.$basket_obj).click(function (event) { event.preventDefault ? event.preventDefault() : event.returnValue = false; event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true; var price_data_index_ptn = new RegExp("_oo_dat_addition_option_price_count_down_([0-9]+)"); var price_data_indexes = price_data_index_ptn.exec(this.id); var price_data_index = price_data_indexes[1]; var index = price_data_indexes[2]; self.add_price_data_count( price_data_index, 'addition_option', index, -1 ); jQuery("input[name='_oo_dat_addition_option_price_count_"+price_data_index+"']", this.$basket_obj).val(self.get_price_data_count( price_data_index, 'addition_option', index )); jQuery("#_oo_dat_addition_option_price_count_text_"+price_data_index+"", this.$basket_obj).html(self.get_price_data_count( price_data_index, 'addition_option', price_data_index )); self.place_once_price(price_data_index, 'addition_option', index); self.place_total_price(); self.warn_wrong_price("addition_option", price_data_index); return; }); // 추가구성 삭제버튼 매핑 jQuery("*[id^='_oo_dat_addition_delete_button_"+idx+"']", this.$basket_obj).click(function (event) { event.preventDefault ? event.preventDefault() : event.returnValue = false; event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true; var price_data_index_ptn = new RegExp("_oo_dat_addition_delete_button_([0-9]+)"); var price_data_indexes = price_data_index_ptn.exec(this.id); var price_data_index = price_data_indexes[1]; var index = price_data_indexes[2]; if ( self.options.PRODUCT_PRICE_ARRAY.addition_options_required[index]=="1" ){ alert("필수 선택항목은 삭제할 수 없습니다.\n다른 추가구성옵션으로 변경하실려면 기본상품을 삭제 후 다시 추가해주십시오."); return; } self.remove_add_option_price_data( price_data_index); self.redrawAdditionOption(); return; }); } } // 선택한 옵션의 한 레코드의 가격 this.get_price_of = function (price_data){ var price = 0; var count = 0; price = price_data.price * price_data.count; count = price_data.count; return {price:price, count:count}; }; // 선택한 주문옵션 html그리기(1개씩 그린다) this.build_element_selected_price = function (seq, price_data) { var result = ""; var main_product = this.STRING_FORMAT.main_product; var count_input = this.STRING_FORMAT.count_input; var skin_image_url = this.options.IMAGE_PATH; // 기본 상품명 main_product = this.replace(main_product, "##MESSAGE_PANEL_ID##", "_oo_dat_warn_message_"+seq); main_product = this.replace(main_product, "##PRODUCT_NAME##", price_data.price_name); main_product = this.replace(main_product, "##PRICE_TEXT##", this.options.CURRENCY_FRONT+this.comma(this.get_one_price(seq, 'product', 0))+this.options.CURRENCY_REAR); main_product = this.replace(main_product, "##DELETE_BUTTON_ID##", '_oo_dat_delete_button_'+seq); main_product = this.replace(main_product, "##PRICE_TEXT_ID##", '_oo_dat_price_text_'+seq); // 기본 상품 수량 객체 셋팅 count_input = this.replace(count_input, "##INPUT_COUNT_NAME##", "_oo_dat_main_price_count["+seq+"]"); count_input = this.replace(count_input, "##INPUT_COUNT_VALUE##", price_data.count); count_input = this.replace(count_input, "##TEXT_COUNT_ID##", "_oo_dat_main_price_count_text_"+seq); count_input = this.replace(count_input, "##TEXT_COUNT_VALUE##", price_data.count); count_input = this.replace(count_input, "##INPUT_COUNT_UP##", "_oo_dat_main_price_count_up_"+seq); count_input = this.replace(count_input, "##INPUT_COUNT_DOWN##", "_oo_dat_main_price_count_down_"+seq); main_product = this.replace(main_product, "##INPUT_COUNT##", count_input); // 필수선택옵션, 입력형 옵션 처리 var non_priced_option_text = ""; var require_option_text = ""; var input_option_text = ""; // 필수선택 옵션 if (( this.options.PRICE_MODE & 2 ) == 2 ){ if ( price_data.require_option.length>0 ){ for ( var i=0; i"+result+""); //alert(result); }; // 선택한 추가옵션 html그리기(1개씩 그린다) this.build_element_selected_price_addition = function (seq, price_addition_data) { var result = ""; var main_product = this.STRING_FORMAT.main_product; var count_input = this.STRING_FORMAT.count_input; var skin_image_url = this.options.IMAGE_PATH; var addition_option_text = ""; var values = price_addition_data.value.split(";"); var priced_options = this.STRING_FORMAT.priced_options; var priced_option_count = this.STRING_FORMAT.count_input; priced_options = this.replace(priced_options, "##PRODUCT_NAME##", price_addition_data.name+": "+values[3]); priced_options = this.replace(priced_options, "##PRICE_TEXT##", this.options.CURRENCY_FRONT+this.comma(this.get_one_price(seq, 'addition_option', seq))+this.options.CURRENCY_REAR); priced_options = this.replace(priced_options, "##PRICE_TEXT_ID##", '_oo_dat_addition_option_price_text_'+seq); priced_options = this.replace(priced_options, "##DELETE_BUTTON_ID##", '_oo_dat_addition_delete_button_'+seq); priced_option_count = this.replace(priced_option_count, "##INPUT_COUNT_NAME##", "_oo_dat_addition_option_price_count_"+seq); priced_option_count = this.replace(priced_option_count, "##INPUT_COUNT_VALUE##", price_addition_data.count); priced_option_count = this.replace(priced_option_count, "##TEXT_COUNT_ID##", "_oo_dat_addition_option_price_count_text_"+seq); priced_option_count = this.replace(priced_option_count, "##TEXT_COUNT_VALUE##", price_addition_data.count); priced_option_count = this.replace(priced_option_count, "##INPUT_COUNT_UP##", "_oo_dat_addition_option_price_count_up_"+seq); priced_option_count = this.replace(priced_option_count, "##INPUT_COUNT_DOWN##", "_oo_dat_addition_option_price_count_down_"+seq); priced_option_count = this.replace(priced_option_count, "##PRICE_ZERO##", (price_addition_data.price > 0) ? '' : '_oo_dat_addition_option_price_zero'); priced_options = this.replace(priced_options, "##INPUT_COUNT##", priced_option_count); addition_option_text += this.STRING_FORMAT.inner_line + priced_options; result = this.replace(this.STRING_FORMAT.selected_price_wrap, "##SELECTED_PRICE_ELEMENTS##", addition_option_text); result = this.replace(result, "##SKIN_IMAGE_URL##", skin_image_url); return result; } // PRICE_DATA의 item(기본상품,checkbox옵션,addition옵션) 수량 변경 this.change_price_data_count = function (price_data_index, item_name, item_index, count) { if (item_name == "addition_option") { if ( !this.PRICE_ADDITION_DATA[price_data_index] ) return; if ( this.PRICE_ADDITION_DATA[price_data_index].value == '' ) return; this.PRICE_ADDITION_DATA[price_data_index].count = count; if ( this.PRICE_ADDITION_DATA[price_data_index].count < 1 ){ this.PRICE_ADDITION_DATA[price_data_index].count = 1; } } else { if ( typeof(this.PRICE_DATA[price_data_index])!="object" ) return; if ( item_name == 'product' ){ this.PRICE_DATA[price_data_index].count = count; if ( this.PRICE_DATA[price_data_index].count < 1 ){ this.PRICE_DATA[price_data_index].count = 1; } }else{ if ( item_name != 'addition_option' ) return; if ( !this.PRICE_DATA[price_data_index][item_name][item_index] ) return; if ( this.PRICE_DATA[price_data_index][item_name][item_index].value == '' ) return; this.PRICE_DATA[price_data_index][item_name][item_index].count = count; if ( this.PRICE_DATA[price_data_index][item_name][item_index].count < 1 ){ this.PRICE_DATA[price_data_index][item_name][item_index].count = 1; } } } }; // PRICE_DATA의 item의(기본상품,checkbox옵션,addition옵션) 수량 반환 this.get_price_data_count = function ( price_data_index, item_name, item_index ) { if (item_name == "addition_option") { return this.PRICE_ADDITION_DATA[price_data_index].count; } else { if ( typeof(this.PRICE_DATA[price_data_index])!='object' ) return 0; if ( item_name == 'product' ){ return this.PRICE_DATA[price_data_index].count; }else{ if ( item_name != 'addition_option' ) return 0; if ( !this.PRICE_DATA[price_data_index][item_name][item_index] ) return 0; if ( this.PRICE_DATA[price_data_index][item_name][item_index].value == '' ) return 0; return this.PRICE_DATA[price_data_index][item_name][item_index].count; } } } // PRICE_DATA item에 수량 추가(감소) this.add_price_data_count = function ( price_data_index, item_name, item_index, add_count ) { var pre_count = this.get_price_data_count(price_data_index, item_name, item_index); this.change_price_data_count (price_data_index, item_name, item_index, pre_count+add_count); }; // price_data 비교(주문옵션 선택한 상태 비교) this.compare_price_data = function (data_a, data_b) { if ( data_a._dat_price == data_b._dat_price ){ if (( this.options.PRICE_MODE & 2) == 2 ){ if ( data_a.require_option.length>0 && data_b.require_option.length>0 ){ for (var i=0; i 0 ? this.PRICE_DATA[price_data_index].order_max : 0; order_min = typeof this.PRICE_DATA[price_data_index].order_min==='number' && this.PRICE_DATA[price_data_index].order_min > 0 ? this.PRICE_DATA[price_data_index].order_min : 0; left_stock = this.PRICE_DATA[price_data_index].stock_count; }else return "SOLDOUT"; // 매개변수 오류 var inputted_all_count = inputted_count = alter_count = alter_count==null ? 0 : alter_count; var currently_selected_product_count = (price_data_index!=null ? this.PRICE_DATA[price_data_index].count : 0); inputted_count += currently_selected_product_count; if ( (this.options.PRICE_MODE & 0) == 0 || (this.options.PRICE_MODE & 2) == 2 || (this.options.PRICE_MODE & 4) == 4 || (this.options.PRICE_MODE & 8) == 8) { for ( var i=0; i 0 && inputted_count < order_min ){ return "SHORTS_ORDER_COUNT"; // 최소구매수량보다 적음 } // 추가된 상품 수량 전체가 재고수량보다 많으면 if ( left_stock > -1 && inputted_all_count > left_stock ){ var available_count = left_stock - (inputted_all_count - alter_count); // currently_selected_product_count가 0이면 새로 추가한다는것을 의미함 if ( currently_selected_product_count==0 ){ if ( available_count > 0 && order_min > 0 && available_count < order_min ){ return "SHORTS_ORDER_COUNT"; // 최소구매수량보다 적음 } } if ( available_count>0 ){ return available_count; } return "INPUTTED_ALL"; // 남은재고 모두 선택된상태 } if ( order_max > 0 && inputted_count > order_max ){ // alter_count보다 적지만 추가 가능한 갯수를 파악한다. var available_count = order_max - (inputted_count - alter_count); if ( available_count>0 ){ return available_count; } return "OVERS_ORDER_COUNT"; // 최대구매수량보다 많음 } if ( left_stock == -1 ){ return "OK"; // 재고무제한 } if ( left_stock == 0 ){ return "SOLDOUT"; // 품절 } return "OK"; // 재고문제없음 }; /********************************************** * EVENT HANDLERS **********************************************/ // 옵션별가격 첫번째 항목 로딩 this.load_option_price1 = function( opt1, opt2 ){ // if ( opt1.options.length > 1 ) return; opt1.disabled = false; jQuery.ajax({ url : './', type : 'POST', dataType : 'JSON', data : { 'act' : 'shop.goods_stock_option_ajax', 'good_seq' : self.options.GOOD_SEQ, 'restock_type' : self.options.RESTOCK_TYPE, 'option_cmd' : 'ICmdValue' }, success : function( data ) { if (data.success){ var option_item = data.items; // 기존에 값이 있으면? 삭제한다. if ( opt1.options.length > 1 ) { for ( var i = opt1.options.length; i > 1; i-- ) opt1.remove(i -1); } if( option_item ) { jQuery.each( option_item, function(i, opt) { var oItem = document.createElement("OPTION"); oItem.value = opt.option_name; oItem.text = opt.option_name; opt1.options.add(oItem); }); } opt1.disabled = false; opt2.disabled = false; }else{ if (typeof data.msg == 'string'){ alert(data.msg); }else{ alert('상품정보를 읽는 중 오류가 발생했습니다.'); } } } }); }; // 옵션별가격 항목1 select change핸들러 this.change_option_price1 = function ( opt1, opt2 ){ if ( opt2.options.length > 1 ) { for ( var i = opt2.options.length; i > 1; i-- ) opt2.remove(i-1); opt2.selectedIndex = 0; } if ( opt1.selectedIndex < 1 ) { return; } var sText = opt2.options[0].text ; // 2번째 옵션 로딩 jQuery.ajax({ url : '/', /* pc,mobile 공용 ajax */ type : 'POST', dataType : 'JSON', data : { 'act' : 'shop.goods_stock_option_ajax', 'good_seq' : self.options.GOOD_SEQ, 'good_cate' : self.options.GOOD_CATE, 'option_type' : opt1.name, 'option_cmd' : 'ICmdCheck', 'option1' : opt1.options[ opt1.selectedIndex ].value }, success : function( data ) { if (data.success){ self.stock_option_info = data.items; jQuery.each( self.stock_option_info, function(index, o) { var price_gap = o.price_gap; if (price_gap != ""){ //price_gap = " (" + self.options.CURRENCY_FRONT + self.comma(price_gap)+self.options.CURRENCY_REAR + ")"; price_gap = " (" + price_gap + ")"; }else{ price_gap = ""; } var oItem = document.createElement("OPTION"); oItem.value = index + ";" + o.option_name; if ( o.stock_count >= 0 ){ // 장바구니 옵션/수량 모드일경우에 // 이미 장바구니에 담겨있는(소진된재고) 수량만큼 재고를 훼이꾸로 더해준다. if ( self.options.MODE == "MODIFY" ){ if ( self.options.DEFAULT_PRICE_DATA!=null && self.options.DEFAULT_PRICE_DATA.length>0 ){ var submit_index = o.submit_index.split(";"); for ( var i=0; i 0 ){ oItem.text = o.option_name + price_gap + " - 재고:"+self.stock_option_info[index].stock_count+"개"; }else if ( self.options.SHOW_STOCKCOUNT && self.stock_option_info[index].stock_count < 0 ){ oItem.text = o.option_name + price_gap + " - 재고무관"; }else{ oItem.text = o.option_name + price_gap; } if ( o.stock_count == 0 || o.good_stock_type == 1) { oItem.text += " (품절)"; oItem.style.backgroundColor = '#EEEEEE'; oItem.style.color = '#777777'; oItem.disabled = true; } else { if (o.stock_count_str!=''){ if (o.good_stock_remain_count_show == 1) { oItem.text += " (잔여 : " + o.stock_count_str + "개)"; } } } opt2.options.add(oItem); }); opt2.options[0].text = sText; opt2.selectedIndex = 0; opt2.disabled = false; opt1.disabled = false; }else{ if (typeof data.msg == 'string'){ alert(data.msg); }else{ alert('상품정보를 읽는 중 오류가 발생했습니다.'); } } } }); }; // 옵션별 가격 항목2 change 이벤트 핸들러 this.change_option_price2 = function ( o ) { if ( o.selectedIndex > 0 ) { var tmp_index = o.options[ o.selectedIndex ].value.split(";"); var i = tmp_index[0]; if ( self.stock_option_info[i].stock_count == 0 ) { o.selectedIndex = 0; } self.change_addition_option_price_text( self.stock_option_info[i].offrate_check=="2" ); } }; // basket_form submit 결과 처리 콜백 함수 this.submit_callback = function (json_data) { if ( json_data.action ){ this.return_value_parse(json_data.action); } if ( json_data.message ){ alert(json_data.message); } if ( json_data.return_url ){ location.href = json_data.return_url; } }; // submit결과 값 파싱 함수 this.return_value_parse = function (obj) { if ( !obj || obj == null ) return; switch ( obj.type ) { case 'MESSAGE': alert(obj.behavior); break; case 'URL': location.href = obj.behavior; break; case 'EVAL': eval(obj.behavior); break; case 'CONFIRM': if ( confirm(obj.behavior.message) ){ this.return_value_parse(obj.behavior['true']); }else{ this.return_value_parse(obj.behavior['false']); } case 'NONE':break; } }; // 가상form element 생성 함수 this.get_virtual_form = function () { if ( this.$virtual_form_obj != null ) return this.$virtual_form_obj; if ( jQuery("#_oo_virtual_form").is("form") ){ this.$virtual_form_obj = jQuery("#_oo_virtual_form"); return this.$virtual_form_obj; } // 생성된적이 없다면 새로 만든다. jQuery(document.body).append("
    "); if ( jQuery("#_oo_virtual_form").is("form") ){ this.$virtual_form_obj = jQuery("#_oo_virtual_form"); return this.$virtual_form_obj; } return null; }; // 장바구니에 담은 후 이동 선택창 출력 함수 this.cart_result = function( data ){ var layer = jQuery('#layer_cart'); if (layer.length > 0) { jQuery(layer).prop('url', data.url); if (jQuery(layer).prop('init') != 1) { // init event jQuery(layer).prop('init', 1); jQuery(layer).appendTo(document.body); jQuery('.layer_cart_close, .layer_cart_cancel', layer).on('click', function() { jQuery(layer).hide(); jQuery('#__block_page__').hide(); if(self.options.IS_POPUP) { window.close(); } }); jQuery('.layer_cart_ok', layer).on('click', function() { jQuery(layer).hide(); jQuery('#__block_page__').hide(); var url = jQuery(layer).prop('url'); if(self.options.IS_POPUP) { opener.location.href = './' + url; window.close(); } else { location.href = './' + url; } }); } if (self.mode == 'WISH') { jQuery(layer) .find('.layer_cart_title, .layer_cart_msg').hide().end() .find('.layer_wish_title, .layer_wish_msg').show().end(); } else { jQuery(layer) .find('.layer_cart_title, .layer_cart_msg').show().end() .find('.layer_wish_title, .layer_wish_msg').hide().end(); } // 20180626 김여로 수정 ( 아이폰 장바구니 레이어팝업 사라지지 않게 하기위해서 top : '400px', 추가 top : '400px', Durian.showLayer(layer, { center : true, block : true }); } else { if (self.mode == 'WISH') { var msg = "선택한 상품을\n관심상품에 담았습니다."; } else { var msg = "선택한 상품을\n장바구니에 담았습니다"; } msg += "\n지금 확인하시겠습니까?"; if (confirm(msg)) { if(self.options.IS_POPUP) { opener.location.href = './' + data.url; window.close(); } else { location.href = './' + data.url; } } else { if(self.options.IS_POPUP) { window.close(); } } } } // 필수 선택 this.applyRequireOptionSet = function (option_type, obj) { if (option_type == 'addition'){ if (self.PRICE_DATA.length <= 0) { alert('주문옵션을 설정해주세요'); obj.selectedIndex = 0; } else { self.viewAddOptionPrice(jQuery(obj)); return; } } else if ( option_type == 'required' ){ var j = 0; var k = 0; // 가격선택, 필수선택 jQuery("select[name^='" +this.options.OPTION_PRICE_NAME1+ "'],select[name^='" +this.options.OPTION_PRICE_NAME2+ "'],select[name^='" +this.options.OPTION_REQUIRE_NAME_FORMAT+ "']", this.$basket_obj).each(function () { if (jQuery(this).attr('require') == '1'){ j++; if ( jQuery(this).val() != ""){ k++; } } }); if (j==k) { if (self.options.GOOD_OPT_SEL_TYPE == 0) { self.viewPrice(); } else if (self.options.GOOD_OPT_SEL_TYPE == 1) { if (obj.id != self.options.OPTION_PRICE_NAME1) { self.viewPrice(); } } } } } /********************************************** * NAVER CHECKOUT **********************************************/ /* * 네이버 페이 구매버튼 클릭 핸들러 */ this.checkout_buy = function () { // 가격 비공개 상태 if ( self.options.PRICE_COUNT == 0 /*공개된가격이 하나도없거나 */ || (self.options.IS_SIMPLE_PRICE && self.SIMPLE_PRICE_GRANT_ERROR) /*단순가격인데 구매등급이아니면*/ ){ if ( self.options.LOGIN_STATE == "1" ){ alert("죄송합니다. 본 상품에 대한 구매 권한이 없습니다.\n\n회원등급을 확인해 주세요"); }else{ alert("죄송합니다. 본 상품에 대한 구매 권한이 없습니다.\n\n회원이시면 로그인 후 재시도 부탁드립니다."); } return; } if ( !self.PRICE_DATA || self.PRICE_DATA.length==0 ){ //alert("네이버 페이 구매하실 가격 및 수량을 선택해주십시오."); alert("주문옵션 정보를 추가하신 후 진행해 주세요."); return; } // 입력형옵션 입력검사 if ( !self.check_input_option() ){ return; } self.mode = 'CHECKOUT'; self.$basket_obj.trigger("submit"); }; /* * 네이버 페이 찜버튼 클릭 핸들러 */ this.checkout_wishlist = function () { var $f = self.get_virtual_form(); if ( $f==null ){ alert("오류가 발생했습니다."); return; } $f.empty(); $f.append(""); if (self.options.IS_MOBILE_MODE) $f.append(""); if (!self.options.IS_MOBILE_MODE) window.open('', 'NC_WIN', 'width=500, height=400, scrollbars=yes'); var f = $f.get(0); f.action = '/partner/naver/checkout/wish.php'; f.method = 'post'; if (!self.options.IS_MOBILE_MODE) f.target = 'NC_WIN'; f.submit(); }; // 네이버 페이 처리 페이지로 전송함수(cart_act_ajax.php에서 호출됨) this.send_sale_to_nc = function (cart_seqs) { var $f = self.get_virtual_form(); if ( $f==null ){ alert("오류가 발생했습니다."); return; } if ( cart_seqs==null || cart_seqs.length==0 ){ alert("오류가 발생했습니다.2"); return; } if (typeof cart_seqs === 'string' ){ if (cart_seqs.indexOf('|')>=0){ cart_seqs = cart_seqs.split('|'); }else{ cart_seqs = [cart_seqs]; } } $f.empty(); $f.append(''); if (self.options.IS_MOBILE_MODE) { $f.append(''); } for ( var i in cart_seqs ) { if ( typeof cart_seqs[i] === 'string'){ $f.append(''); } } var f = $f.get(0); f.action = "/partner/naver/checkout/order.php"; f.method = 'post'; fc__oo_virtual_form = new Form.Checker({'form':'_oo_virtual_form'}); fc__oo_virtual_form.useHiddenAct = true; fc__oo_virtual_form.doSubmit(); }; /********************************************** * Util Methods **********************************************/ this.replace = function (str, src, dest) { return str.split(src).join(dest);}; this.var_dump = function (data, depth) { var text = '';if ( depth == null ) depth = 0; if ( typeof data == 'object' ){ for ( var k in data ) { tab = "";for(var d=0;d\n##SELECTED_PRICE_ELEMENTS##\n", 'count_input' : format_count_input, 'main_product' : format_main_product, 'priced_options' : format_priced_options, 'inner_line' : '' }; // 그거..뭐라 이름지을 수가 없네 merge this.STRING_FORMAT = jQuery.extend({}, this.STRING_FORMAT_DEFAULT, options.STRING_FORMAT); // 초기화 this.init(); }; return _class; }) (jQuery);