장바구리에서 옵션 수정 기능 추가

This commit is contained in:
chicpro
2013-05-27 18:18:47 +09:00
parent ff5e73e6e2
commit 05b9a02dfb
5 changed files with 320 additions and 18 deletions

View File

@ -1,6 +1,6 @@
$(function() {
// 선택옵션
$("select[name='it_option[]']").change(function() {
$("select[name='it_option[]']").live("change", function() {
var sel_count = $("select[name='it_option[]']").size();
var idx = $("select[name='it_option[]']").index($(this));
var val = $(this).val();
@ -57,19 +57,19 @@ $(function() {
});
// 추가옵션
$("select[name='it_supply[]']").change(function() {
$("select[name='it_supply[]']").live("change", function() {
var $el = $(this);
// 선택옵션 자동추가 기능을 사용하려면 아래 false를 true로 설정
sel_supply_process($el, false);
});
// 선택옵션 추가
$("#sit_selopt_submit").click(function() {
$("#sit_selopt_submit").live("click", function() {
sel_option_process(true);
});
// 추가옵션 추가
$("button.sit_sel_submit").click(function() {
$("button.sit_sel_submit").live("click", function() {
var $el = $(this).closest("td").find("select[name='it_supply[]']");
sel_supply_process($el, true);
});
@ -118,14 +118,11 @@ $(function() {
if($el.hasClass("sit_opt_list")) {
if($(".sit_opt_list").size() <= 1)
del_exec = false;
} else {
if($(".sit_opt_list").size() < 1)
del_exec = false;
}
}
if(del_exec) {
$(this).closest("li").remove();
$el.closest("li").remove();
price_calculate();
} else {
alert("선택옵션은 하나이상이어야 합니다.");

View File

@ -683,7 +683,7 @@ function print_item_options($it_id, $uq_id)
{
global $g4;
$sql = " select ct_option from {$g4['shop_cart_table']} where it_id = '$it_id' and uq_id = '$uq_id' order by ct_num asc ";
$sql = " select ct_option from {$g4['shop_cart_table']} where it_id = '$it_id' and uq_id = '$uq_id' order by io_type asc, ct_num asc, ct_id asc ";
$result = sql_query($sql);
$str = '';

161
shop/cartoption.php Normal file
View File

@ -0,0 +1,161 @@
<?php
include_once('./_common.php');
$it_id = $_POST['it_id'];
$idx = $_POST['idx'];
$sql = " select it_id, it_option_subject, it_supply_subject
from {$g4['shop_item_table']}
where it_id = '$it_id'
and it_use = '1' ";
$it = sql_fetch($sql);
if(!$it['it_id'])
die('no-item');
// 장바구니 자료
$uq_id = get_session('ss_uq_id');
$sql = " select * from {$g4['shop_cart_table']} where uq_id = '$uq_id' and it_id = '$it_id' order by io_type asc, ct_num asc, ct_id asc ";
$result = sql_query($sql);
// 판매가격
$sql2 = " select ct_price, it_name from {$g4['shop_cart_table']} where uq_id = '$uq_id' and it_id = '$it_id' and ct_num = '0' ";
$row2 = sql_fetch($sql2);
if(!mysql_num_rows($result))
die('no-cart');
?>
<form name="foption" method="post" action="<?php echo G4_SHOP_URL; ?>/cartupdate.php" onsubmit="return formcheck();">
<input type="hidden" name="act" value="optionmod">
<input type="hidden" name="it_id" value="<?php echo $it['it_id']; ?>">
<input type="hidden" name="it_price" value="<?php echo $row2['ct_price']; ?>">
<input type="hidden" name="it_name" value="<?php echo $row2['it_name']; ?>">
<input type="hidden" name="total_price" value="">
<input type="hidden" name="sw_direct">
<?php
$option_1 = get_item_options($it['it_id'], $it['it_option_subject']);
if($option_1) {
?>
<section>
<h3>선택옵션</h3>
<table class="sit_ov_tbl">
<colgroup>
<col class="grid_3">
<col>
</colgroup>
<tbody>
<?php // 선택옵션
echo $option_1;
?>
</tbody>
</table>
<div class="sit_sel_btn">
<button type="button" id="sit_selopt_submit" class="btn_frmline">추가</button>
</div>
</section>
<?php
}
?>
<?php
$option_2 = get_item_supply($it['it_id'], $it['it_supply_subject']);
if($option_2) {
?>
<section>
<h3>추가옵션</h3>
<table class="sit_ov_tbl">
<colgroup>
<col class="grid_3">
<col>
</colgroup>
<tbody>
<?php // 추가옵션
echo $option_2;
?>
</tbody>
</table>
</section>
<?php
}
?>
<div id="sit_sel_option">
<ul id="sit_opt_added">
<?php
for($i=0; $row=sql_fetch_array($result); $i++) {
if(!$row['io_id'])
$it_stock_qty = get_it_stock_qty($row['it_id']);
else
$it_stock_qty = get_option_stock_qty($row['it_id'], $row['io_id'], $row['io_type']);
if($row['io_price'] < 0)
$io_price = '('.number_format($row['io_price']).'원)';
else
$io_price = '(+'.number_format($row['io_price']).'원)';
$cls = 'opt';
if($row['io_type'])
$cls = 'spl';
?>
<li class="sit_<?php echo $cls; ?>_list">
<input type="hidden" name="ct_id[]" value="<?php echo $row['ct_id']; ?>">
<input type="hidden" name="io_type[]" value="<?php echo $row['io_type']; ?>">
<input type="hidden" name="io_id[]" value="<?php echo $row['io_id']; ?>">
<input type="hidden" name="io_value[]" value="<?php echo $row['ct_option']; ?>">
<input type="hidden" name="io_price[]" value="<?php echo $row['io_price']; ?>">
<input type="hidden" name="io_stock[]" value="<?php echo $it_stock_qty; ?>">
<span class="sit_opt_subj"><?php echo $row['ct_option']; ?></span>
<span class="sit_opt_prc"><?php echo $io_price; ?></span>
<div>
<input type="text" name="ct_qty[]" value="<?php echo $row['ct_qty']; ?>" class="frm_input" size="5">
<button type="button" class="sit_qty_plus btn_frmline">증가</button>
<button type="button" class="sit_qty_minus btn_frmline">감소</button>
<button type="button" class="btn_frmline">삭제</button>
</div>
</li>
<?php
}
?>
</ul>
</div>
<div id="sit_tot_price"></div>
<div>
<input type="submit" value="선택사항적용">
<button type="button" id="mod_option_close">닫기</button>
</div>
</form>
<script>
function formcheck()
{
var val, result = true;
$("li input[name='ct_qty[]']").each(function() {
val = $(this).val();
if(val.length < 1) {
alert("수량을 입력해 주십시오.");
result = false;
return false;
}
if(val.replace(/[0-9]/g, "").length > 0) {
alert("수량은 숫자로 입력해 주십시오.");
result = false;
return false;
}
if(parseInt(val.replace(/[^0-9]/g, "")) < 1) {
alert("수량은 1이상 입력해 주십시오.");
result = false;
return false;
}
});
if(!result)
return false;
f.submit();
}
</script>

View File

@ -14,6 +14,8 @@ else
$colspan = 6;
?>
<script src="<?php echo G4_JS_URL; ?>/shop.js"></script>
<form name="frmcartlist" method="post">
<table class="basic_tbl">
<thead>
@ -236,6 +238,19 @@ if ($s_page == 'cart.php') {
$(function() {
// 선택사항수정
$(".mod_options").click(function() {
var it_id = $(this).closest("tr").find("input[name^=it_id]").val();
var idx = $(".mod_options").index($(this));
$.post(
"./cartoption.php",
{ it_id: it_id, idx: idx },
function(data) {
$("#mod_option_frm").remove();
$(".mod_options:eq("+idx+")").after("<div id=\"mod_option_frm\"></div>");
$("#mod_option_frm").html(data);
price_calculate();
}
);
});
// 모두선택
@ -245,6 +260,11 @@ $(function() {
else
$("input[name^=ct_chk]").attr("checked", false);
});
// 옵션수정 닫기
$("#mod_option_close").live("click", function() {
$("#mod_option_frm").remove();
});
});
function form_check(act) {

View File

@ -124,7 +124,7 @@ else if ($act == "multi") // 온라인견적(등)에서 여러개의 상품이
sql_query($sql);
}
}
else // 장바구니에 담기
else if ($act == "optionmod") // 장바구니에서 옵션변경
{
if (!$_POST['it_id'])
alert('장바구니에 담을 상품을 선택하여 주십시오.');
@ -213,21 +213,145 @@ else // 장바구니에 담기
sql_query(" ALTER TABLE `{$g4['shop_cart_table']}` ADD `ct_direct` TINYINT NOT NULL ");
}
// 기존 장바구니 자료를 먼저 삭제
sql_query(" delete from {$g4['shop_cart_table']} where uq_id = '$tmp_uq_id' and it_id = '$it_id' ");
// 포인트 사용하지 않는다면
if (!$config['cf_use_point']) { $_POST['it_point'] = 0; }
// 장바구니에 Insert
$comma = '';
$sql = " INSERT INTO {$g4['shop_cart_table']}
( uq_id, it_id, it_name, ct_status, ct_price, ct_point, ct_point_use, ct_stock_use, ct_option, ct_qty, ct_num, io_id, io_type, io_price, ct_time, ct_ip, ct_direct )
VALUES ";
if(count($_POST['io_id'])) {
$comma = '';
$sql = " INSERT INTO {$g4['shop_cart_table']}
( uq_id, it_id, it_name, ct_status, ct_price, ct_point, ct_point_use, ct_stock_use, ct_option, ct_qty, ct_num, io_id, io_type, io_price, ct_time, ct_ip, ct_direct )
VALUES ";
for($i=0; $i<$option_count; $i++) {
$sql .= $comma."( '$tmp_uq_id', '{$_POST['it_id']}', '{$_POST['it_name']}', '쇼핑', '{$_POST['it_price']}', '{$_POST['it_point']}', '0', '0', '{$_POST['io_value'][$i]}', '{$_POST['ct_qty'][$i]}', '$i', '{$_POST['io_id'][$i]}', '{$_POST['io_type'][$i]}', '{$_POST['io_price'][$i]}', '".G4_TIME_YMDHIS."', '$REMOTE_ADDR', '$sw_direct' )";
$comma = ' , ';
for($i=0; $i<$option_count; $i++) {
$sql .= $comma."( '$tmp_uq_id', '{$_POST['it_id']}', '{$_POST['it_name']}', '쇼핑', '{$_POST['it_price']}', '{$_POST['it_point']}', '0', '0', '{$_POST['io_value'][$i]}', '{$_POST['ct_qty'][$i]}', '$i', '{$_POST['io_id'][$i]}', '{$_POST['io_type'][$i]}', '{$_POST['io_price'][$i]}', '".G4_TIME_YMDHIS."', '$REMOTE_ADDR', '$sw_direct' )";
$comma = ' , ';
}
sql_query($sql);
}
}
else // 장바구니에 담기
{
if (!$_POST['it_id'])
alert('장바구니에 담을 상품을 선택하여 주십시오.');
sql_query($sql);
$option_count = count($_POST['io_id']);
if($option_count) {
if($_POST['io_type'][0] != 0)
alert('상품의 선택옵션을 선택해 주십시오.');
for($i=0; $i<count($_POST['ct_qty']); $i++) {
if ($_POST['ct_qty'][$i] < 1)
alert('수량은 1 이상 입력해 주십시오.');
}
//--------------------------------------------------------
// 변조 검사
//--------------------------------------------------------
$total_price = 0;
$sql = " select * from {$g4['shop_item_table']} where it_id = '{$_POST['it_id']}' ";
$it = sql_fetch($sql);
// 옵션정보를 얻어서 배열에 저장
$opt_list = array();
$sql = " select * from {$g4['shop_item_option_table']} where it_id = '{$_POST['it_id']}' and io_use = '1' order by io_no asc ";
$result = sql_query($sql);
for($i=0; $row=sql_fetch_array($result); $i++) {
$opt_list[$row['io_type']][$row['io_id']]['price'] = $row['io_price'];
$opt_list[$row['io_type']][$row['io_id']]['stock'] = $row['io_stock_qty'];
}
for($i=0; $i<$option_count; $i++) {
$opt_id = $_POST['io_id'][$i];
$opt_type = $_POST['io_type'][$i];
$opt_price = $_POST['io_price'][$i];
$opt_qty = $_POST['ct_qty'][$i];
if((int)$opt_price !== (int)$opt_list[$opt_type][$opt_id]['price'])
die("Option Price Mismatch");
if($opt_type == 1)
$total_price += $opt_price * $opt_qty;
else
$total_price += ($it['it_price'] + $opt_price) * $opt_qty;
}
// 상품 총금액이 다름
if ((int)$_POST['total_price'] !== (int)$total_price)
die("Error..");
$point = $it['it_point'];
// 포인트가 다름
if ((int)$point !== (int)$_POST['it_point'] && $config['cf_use_point'])
die("Error...");
//--------------------------------------------------------
//--------------------------------------------------------
// 재고 검사
//--------------------------------------------------------
// 이미 장바구니에 있는 같은 상품의 수량합계를 구한다.
for($i=0; $i<$option_count; $i++) {
$sql = " select SUM(ct_qty) as cnt from {$g4['shop_cart_table']}
where it_id = '{$_POST['it_id']}'
and uq_id = '$tmp_uq_id'
and io_id = '{$_POST['io_id'][$i]}' ";
$row = sql_fetch($sql);
$sum_qty = $row['cnt'];
// 재고 구함
$ct_qty = $_POST['ct_qty'][$i];
if(!$_POST['io_id'][$i])
$it_stock_qty = get_it_stock_qty($_POST['it_id']);
else
$it_stock_qty = get_option_stock_qty($_POST['it_id'], $_POST['io_id'][$i], $_POST['io_type'][$i]);
if ($ct_qty + $sum_qty > $it_stock_qty)
{
alert($_POST['io_value'][$i]." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty) . "");
}
}
//--------------------------------------------------------
// 바로구매에 있던 장바구니 자료를 지운다.
$result = sql_query(" delete from {$g4['shop_cart_table']} where uq_id = '$tmp_uq_id' and ct_direct = 1 ", false);
if (!$result) {
// 삭제중 에러가 발생했다면 필드가 없다는 것이므로 바로구매 필드를 생성한다.
sql_query(" ALTER TABLE `{$g4['shop_cart_table']}` ADD `ct_direct` TINYINT NOT NULL ");
}
// 포인트 사용하지 않는다면
if (!$config['cf_use_point']) { $_POST['it_point'] = 0; }
// 장바구니에 Insert
$sql = " select ct_num
from {$g4['shop_cart_table']}
where it_id = '{$_POST['it_id']}'
and uq_id = '$tmp_uq_id'
order by ct_num desc ";
$row = sql_fetch($sql);
if($row['ct_num'] != '')
$ct_num = (int)$row['ct_num'] + 1;
else
$ct_num = 0;
$comma = '';
$sql = " INSERT INTO {$g4['shop_cart_table']}
( uq_id, it_id, it_name, ct_status, ct_price, ct_point, ct_point_use, ct_stock_use, ct_option, ct_qty, ct_num, io_id, io_type, io_price, ct_time, ct_ip, ct_direct )
VALUES ";
for($i=0; $i<$option_count; $i++) {
$sql .= $comma."( '$tmp_uq_id', '{$_POST['it_id']}', '{$_POST['it_name']}', '쇼핑', '{$_POST['it_price']}', '{$_POST['it_point']}', '0', '0', '{$_POST['io_value'][$i]}', '{$_POST['ct_qty'][$i]}', '$ct_num', '{$_POST['io_id'][$i]}', '{$_POST['io_type'][$i]}', '{$_POST['io_price'][$i]}', '".G4_TIME_YMDHIS."', '$REMOTE_ADDR', '$sw_direct' )";
$comma = ' , ';
$ct_num++;
}
sql_query($sql);
}
}
// 바로 구매일 경우