#176 사용자 옵션 출력 추가 중

This commit is contained in:
chicpro
2013-05-23 18:31:15 +09:00
parent b027c88c61
commit 979af49812
4 changed files with 267 additions and 50 deletions

View File

@ -305,26 +305,25 @@ sql_query(" delete from {$g4['shop_item_option_table']} where io_type = '0' and
$option_count = count($_POST['opt_id']);
if($option_count) {
// 실재하는 1차 옵션항목
$arr_opt1 = array();
$opt2_cnt = $opt3_cnt = 0;
// 옵션명
$opt1_cnt = $opt2_cnt = $opt3_cnt = 0;
for($i=0; $i<$option_count; $i++) {
$opt_val = explode(chr(30), $_POST['opt_id'][$i]);
if(!in_array($opt_val[0], $arr_opt1))
$arr_opt1[] = $opt_val[0];
if($opt_val[0])
$opt1_cnt++;
if($opt_val[1])
$opt2_cnt++;
if($opt_val[2])
$opt3_cnt++;
}
$it_option_subject = $opt1_subject;
if($opt2_subject && $opt2_cnt)
$it_option_subject .= ','.$opt2_subject;
if($opt3_subject && $opt3_cnt)
$it_option_subject .= ','.$opt3_subject;
$it_option = implode(',', $arr_opt1);
if($opt1_subject && $opt1_cnt) {
$it_option_subject = $opt1_subject;
if($opt2_subject && $opt2_cnt)
$it_option_subject .= ','.$opt2_subject;
if($opt3_subject && $opt3_cnt)
$it_option_subject .= ','.$opt3_subject;
}
}
// 추가옵션
@ -360,7 +359,6 @@ $sql_common = " ca_id = '$ca_id',
it_maker = '$it_maker',
it_origin = '$it_origin',
it_option_subject = '$it_option_subject',
it_option = '$it_option',
it_supply_subject = '$it_supply_subject',
it_type1 = '$it_type1',
it_type2 = '$it_type2',

View File

@ -518,46 +518,67 @@ function get_item_options($it_id, $subject)
$str = '';
$subj = explode(',', $subject);
$subj_count = count($subj);
$options = array();
// 옵션항목 배열에 저장
for($i=0; $row=sql_fetch_array($result); $i++) {
$opt_id = explode(chr(30), $row['io_id']);
if($subj_count > 1) {
$options = array();
for($k=0; $k<$subj_count; $k++) {
if(!is_array($options[$k]))
$options[$k] = array();
// 옵션항목 배열에 저장
for($i=0; $row=sql_fetch_array($result); $i++) {
$opt_id = explode(chr(30), $row['io_id']);
if($opt_id[$k] && !in_array($opt_id[$k], $options[$k]))
$options[$k][] = $opt_id[$k];
}
}
for($k=0; $k<$subj_count; $k++) {
if(!is_array($options[$k]))
$options[$k] = array();
// 옵션선택목록 만들기
for($i=0; $i<$subj_count; $i++) {
$opt = $options[$i];
$opt_count = count($opt);
$disabled = '';
if($opt_count) {
$seq = $i + 1;
if($i > 0)
$disabled = ' disabled="disabled"';
$str .= '<tr>'.PHP_EOL;
$str .= '<th><label for="it_option_'.$seq.'">'.$subj[$i].'</label></th>'.PHP_EOL;
$select = '<select name="it_option[]" id="it_option_'.$seq.'"'.$disabled.'>'.PHP_EOL;
$select .= '<option value="">선택</option>'.PHP_EOL;
for($k=0; $k<$opt_count; $k++) {
$opt_val = $opt[$k];
if($opt_val) {
$select .= '<option value="'.$opt_val.'">'.$opt_val.'</option>'.PHP_EOL;
}
if($opt_id[$k] && !in_array($opt_id[$k], $options[$k]))
$options[$k][] = $opt_id[$k];
}
$select .= '</select>'.PHP_EOL;
$str .= '<td>'.$select.'</td>'.PHP_EOL;
$str .= '</tr>'.PHP_EOL;
}
// 옵션선택목록 만들기
for($i=0; $i<$subj_count; $i++) {
$opt = $options[$i];
$opt_count = count($opt);
$disabled = '';
if($opt_count) {
$seq = $i + 1;
if($i > 0)
$disabled = ' disabled="disabled"';
$str .= '<tr>'.PHP_EOL;
$str .= '<th><label for="it_option_'.$seq.'">'.$subj[$i].'</label></th>'.PHP_EOL;
$select = '<select name="it_option[]" id="it_option_'.$seq.'"'.$disabled.'>'.PHP_EOL;
$select .= '<option value="">선택</option>'.PHP_EOL;
for($k=0; $k<$opt_count; $k++) {
$opt_val = $opt[$k];
if($opt_val) {
$select .= '<option value="'.$opt_val.'">'.$opt_val.'</option>'.PHP_EOL;
}
}
$select .= '</select>'.PHP_EOL;
$str .= '<td>'.$select.'</td>'.PHP_EOL;
$str .= '</tr>'.PHP_EOL;
}
}
} else {
$str .= '<tr>'.PHP_EOL;
$str .= '<th><label for="it_option_1">'.$subj[0].'</label></th>'.PHP_EOL;
$select = '<select name="it_option[]" id="it_option_1">'.PHP_EOL;
$select .= '<option value="">선택</option>'.PHP_EOL;
for($i=0; $row=sql_fetch_array($result); $i++) {
if($row['io_price'] >= 0)
$price = '&nbsp;&nbsp;+ '.number_format($row['io_price']).'원';
else
$price = '&nbsp;&nbsp; '.number_format($row['io_price']).'원';
$select .= '<option value="'.$row['io_id'].','.$row['io_price'].','.$row['io_stock_qty'].'">'.$row['io_id'].$price.'</option>'.PHP_EOL;
}
$select .= '</select>'.PHP_EOL;
$str .= '<td>'.$select.'</td>'.PHP_EOL;
$str .= '</tr>'.PHP_EOL;
}
return $str;
@ -593,8 +614,14 @@ function get_item_supply($it_id, $subject)
if($opt_id[0] && !array_key_exists($opt_id[0], $options))
$options[$opt_id[0]] = array();
if($opt_id[1] && !in_array($opt_id[1], $options[$opt_id[0]]))
$options[$opt_id[0]][] = $opt_id[1];
if($opt_id[1]) {
if($row['io_price'] >= 0)
$price = '&nbsp;&nbsp;+ '.number_format($row['io_price']).'원';
else
$price = '&nbsp;&nbsp; '.number_format($row['io_price']).'원';
$options[$opt_id[0]][] = '<option value="'.$opt_id[1].','.$row['io_price'].','.$row['io_stock_qty'].'">'.$opt_id[1].$price.'</option>';
}
}
// 옵션항목 만들기
@ -611,7 +638,7 @@ function get_item_supply($it_id, $subject)
for($k=0; $k<$opt_count; $k++) {
$opt_val = $opt[$k];
if($opt_val) {
$select .= '<option value="'.$opt_val.'">'.$opt_val.'</option>'.PHP_EOL;
$select .= $opt_val.PHP_EOL;
}
}
$select .= '</select>'.PHP_EOL;

View File

@ -171,6 +171,7 @@ function pg_anchor($anc_id) {
<?php } ?>
<script src="<?php echo G4_JS_URL; ?>/md5.js"></script>
<script src="<?php echo G4_JS_URL; ?>/shop.js"></script>
<?php
if (G4_HTTPS_DOMAIN)
@ -326,6 +327,157 @@ else
echo get_item_supply($it['it_id'], $it['it_supply_subject']);
?>
<tr>
<td colspan="2">
<div id="sit_sel_option"></div>
<script>
$(function() {
// 선택옵션
$("select[name='it_option[]']").change(function() {
var sel_count = $("select[name='it_option[]']").size();
var idx = $("select[name='it_option[]']").index($(this));
var val = $(this).val();
// 선택값이 없을 경우 하위 옵션은 disabled
if(val == "") {
$("select[name='it_option[]']:gt("+idx+")").val("").attr("disabled", true);
return;
}
// 하위선택옵션로드
if(sel_count > 1 && (idx + 1) < sel_count) {
var opt_id = "";
// 상위 옵션의 값을 읽어 옵션id 만듬
if(idx > 0) {
$("select[name='it_option[]']:lt("+idx+")").each(function() {
if(!opt_id)
opt_id = $(this).val();
else
opt_id += chr(30)+$(this).val();
});
opt_id += chr(30)+val;
} else if(idx == 0) {
opt_id = val;
}
$.post(
"<?php echo G4_SHOP_URL; ?>/itemoption.php",
{ it_id: "<?php echo $it['it_id']; ?>", opt_id: opt_id, idx: idx, sel_count: sel_count },
function(data) {
$("select[name='it_option[]']").eq(idx+1).empty().html(data).attr("disabled", false);
// select의 옵션이 변경됐을 경우 하위 옵션 disabled
if(idx+1 < sel_count) {
var idx2 = idx + 1;
$("select[name='it_option[]']:gt("+idx2+")").val("").attr("disabled", true);
}
}
);
} else if((idx + 1) == sel_count) { // 선택옵션처리
var info = val.split(",");
// 재고체크
if(parseInt(info[2]) < 1) {
alert("선택하신 선택옵션상품은 재고가 부족하여 구매할 수 없습니다.");
return false;
}
var id = "";
var value, sel_opt, item, price, stock, run_error = false;
var option = sep = "";
$("select[name='it_option[]']").each(function(index) {
value = $(this).val();
item = $(this).closest("tr").find("th label").text();
if(!value) {
run_error = true;
return false;
}
// 옵션선택정보
sel_opt = value.split(",")[0];
if(id == "") {
id = sel_opt;
} else {
id += chr(30)+sel_opt;
sep = " / ";
}
option += sep + item + ":" + sel_opt;
});
if(run_error) {
alert(item+"을(를) 선택해 주십시오.");
return false;
}
price = info[1];
stock = info[2];
add_sel_option(0, id, option, price, stock);
}
});
// 추가옵션
$("select[name='it_supply[]']").change(function() {
var val = $(this).val();
var info = val.split(",");
// 재고체크
if(parseInt(info[2]) < 1) {
alert("선택하신 추가옵션상품은 재고가 부족하여 구매할 수 없습니다.");
return false;
}
var item = $(this).closest("tr").find("th label").text();
var id = item+chr(30)+info[0];
var option = item+":"+info[0];
var price = info[1];
var stock = info[2];
add_sel_option(1, id, option, price, stock);
});
});
function add_sel_option(type, id, option, price, stock)
{
var opt = "";
var li_class = "sit_opt_list";
if(type)
li_class = "sit_spl_list";
var opt_prc;
if(parseInt(price) >= 0)
opt_prc = "(+"+number_format(String(price))+"원)";
else
opt_prc = "("+number_format(String(price))+"원)";
opt += "<li class=\""+li_class+"\">\n";
opt += "<input type=\"hidden\" name=\"io_type[]\" value=\""+type+"\">\n";
opt += "<input type=\"hidden\" name=\"io_id[]\" value=\""+id+"\">\n";
opt += "<input type=\"hidden\" name=\"io_value[]\" value=\""+option+"\">\n";
opt += "<input type=\"hidden\" name=\"io_price[]\" value=\""+price+"\">\n";
opt += "<input type=\"hidden\" name=\"io_stock[]\" value=\""+stock+"\">\n";
opt += "<span class=\"sit_opt_subj\">"+option+"</span>\n";
opt += "<span class=\"sit_opt_prc\">"+opt_prc+"</span>\n";
opt += "<input type=\"text\" name=\"ct_qty[]\" value=\"1\" size=\"5\">\n";
opt += "<button type=\"button\" class=\"sit_qty_plus\">증가</button>\n";
opt += "<button type=\"button\" class=\"sit_qty_minus\">감소</button>\n";
opt += "<button type=\"button\" class=\"sit_opt_del\">삭제</button>\n";
opt += "</li>\n";
if($("#sit_sel_option > ul").size() < 1) {
$("#sit_sel_option").html("<ul></ul>");
$("#sit_sel_option > ul").html(opt);
} else{
$("#sit_sel_option > ul li:last").after(opt);
}
}
</script>
</td>
</tr>
<tr>
<th scope="row">수량</th>
<td>

40
shop/itemoption.php Normal file
View File

@ -0,0 +1,40 @@
<?php
include_once('./_common.php');
$sql = " select * from {$g4['shop_item_option_table']}
where io_type = '0'
and it_id = '$it_id'
and io_use = '1'
and io_id like '$opt_id%'
order by io_no asc ";
$result = sql_query($sql);
$str = '<option value="">선택</option>';
$opt = array();
for($i=0; $row=sql_fetch_array($result); $i++) {
$val = explode(chr(30), $row['io_id']);
$key = $idx + 1;
if(!$val[$key])
continue;
if(in_array($val[$key], $opt))
continue;
$opt[] = $val[$key];
if($key + 1 < $sel_count) {
$str .= PHP_EOL.'<option value="'.$val[$key].'">'.$val[$key].'</option>';
} else {
if($row['io_price'] >= 0)
$price = '&nbsp;&nbsp;+ '.number_format($row['io_price']).'원';
else
$price = '&nbsp;&nbsp; '.number_format($row['io_price']).'원';
$str .= PHP_EOL.'<option value="'.$val[$key].','.$row['io_price'].','.$row['io_stock_qty'].'">'.$val[$key].$price.'</otpion>';
}
}
echo $str;
?>