first commit 2

This commit is contained in:
hmw1001
2026-06-11 18:47:38 +09:00
parent c768729ce6
commit 6f534e33a6
11095 changed files with 1595758 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
<?php
include_once('./_common.php');
// 장바구니에 상품 담기
$it_id = $_POST['it_id'];
$ct_qty = $_POST['ct_qty'];
$sw_direct = $_POST['sw_direct'];
// 💡 [수정] 바로구매일 경우 별도의 세션 변수 사용 (그누보드 표준 로직)
if ($sw_direct) {
$cart_id = get_session('ss_cart_direct');
if (!$cart_id) {
$cart_id = get_uniqid();
set_session('ss_cart_direct', $cart_id);
}
// 💡 [추가] 바로구매 시, 다른 상품들은 선택 해제하여 현재 상품만 주문되도록 보장
sql_query("UPDATE {$g5['g5_shop_cart_table']} SET ct_select = 0 WHERE od_id = '$cart_id'");
} else {
$cart_id = get_session('ss_cart_id');
if (!$cart_id) {
$cart_id = get_uniqid();
set_session('ss_cart_id', $cart_id);
}
}
for($i=0; $i<count($it_id); $i++) {
$id = $it_id[$i];
$qty = isset($ct_qty[$id]) ? (int)$ct_qty[$id] : 0;
if ($qty < 1) {
alert('수량은 1개 이상 입력해 주십시오.');
}
$it = get_shop_item($id, true);
if (!$it['it_id']) {
alert('상품정보가 존재하지 않습니다.');
}
// 💡 [추가] 재고 및 수량 제한 체크 시작
// 품절체크
if ($it['it_soldout']) {
alert('이 상품은 현재 품절입니다.');
}
// 최소, 최대 구매수량 체크
if ($it['it_buy_min_qty'] && $qty < $it['it_buy_min_qty']) {
alert('이 상품은 최소 '.$it['it_buy_min_qty'].'개 이상 구매하셔야 합니다.');
}
if ($it['it_buy_max_qty'] && $qty > $it['it_buy_max_qty']) {
alert('이 상품은 최대 '.$it['it_buy_max_qty'].'개 이하로 구매하셔야 합니다.');
}
// 재고체크
$stock_qty = get_it_stock_qty($id);
if ($qty > $stock_qty) {
alert('이 상품의 재고가 부족합니다.\\n현재 재고: '.number_format($stock_qty).'개');
}
// 💡 [추가] 재고 및 수량 제한 체크 끝
// 장바구니에 동일 상품이 있는지 확인
$sql = " select ct_id, ct_qty from {$g5['g5_shop_cart_table']}
where od_id = '$cart_id' and it_id = '$id' ";
$row = sql_fetch($sql);
if ($row['ct_id']) {
$sum_qty = $row['ct_qty'] + $qty;
// 💡 [추가] 장바구니에 담긴 수량과 합산하여 재고 및 최대수량 다시 체크
if ($it['it_buy_max_qty'] && $sum_qty > $it['it_buy_max_qty']) {
alert('이 상품은 최대 '.$it['it_buy_max_qty'].'개 이하로 구매하셔야 합니다.\\n현재 장바구니에 '.number_format($row['ct_qty']).'개가 담겨있습니다.');
}
if ($sum_qty > $stock_qty) {
alert('이 상품의 재고가 부족합니다.\\n현재 재고: '.number_format($stock_qty).'개, 현재 장바구니: '.number_format($row['ct_qty']).'개');
}
// 있으면 수량 증가 및 상태 업데이트
$sql = " update {$g5['g5_shop_cart_table']}
set ct_qty = ct_qty + '$qty',
ct_direct = '$sw_direct',
ct_select = '1',
ct_select_time = '".G5_TIME_YMDHIS."'
where ct_id = '{$row['ct_id']}' ";
} else {
// 없으면 새로 추가
$sql = " insert into {$g5['g5_shop_cart_table']}
set od_id = '$cart_id',
mb_id = '{$member['mb_id']}',
it_id = '$id',
it_name = '".addslashes($it['it_name'])."',
ct_status = '쇼핑',
ct_price = '".get_price($it)."',
ct_point = '{$it['it_point']}',
ct_point_use = 0,
ct_stock_use = 0,
ct_qty = '$qty',
ct_time = '".G5_TIME_YMDHIS."',
ct_ip = '{$_SERVER['REMOTE_ADDR']}',
ct_send_cost = 0,
ct_direct = '$sw_direct',
ct_select = '1',
ct_select_time = '".G5_TIME_YMDHIS."' ";
}
sql_query($sql);
}
if ($sw_direct) { // 바로구매
goto_url(G5_SHOP_URL.'/orderform.php?sw_direct=1');
} else { // 장바구니
goto_url(G5_SHOP_URL.'/cart.php');
}
?>