지금 장바구니 전체를 불러오는데 체크된 값만 가져오게
본문
// 예약 상품
$sql = " select ct_reserve, ct_normal, it_id
from {$g5['g5_shop_cart_table']}
where od_id = '$tmp_cart_id' ";
$result = sql_query($sql);
while ($row=sql_fetch_array($result)) {
$sql = " select SUM(ct_reserve) as reserve, SUM(ct_normal) as normal
from {$g5['g5_shop_cart_table']}
where od_id = '$tmp_cart_id'
and it_id = '{$row['it_id']}' ";
$sum = sql_fetch($sql);
$tot_reserve+= $sum['reserve'];
$tot_normal+= $sum['normal'];
}
if ( $tot_normal > 0 && $tot_reserve > 0 ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');
이렇게 하니까 각 값이 합산이 되긴 하는데
장바구니에서 전체값을 다 불러오네요
체크된 값만 불러오게 할 수 있나요?
해당 액션 전문입니다
if($act == "buy")
{
if(!count($_POST['ct_chk']))
alert("주문하실 상품을 하나이상 선택해 주십시오.");
// 선택필드 초기화
$sql = " update {$g5['g5_shop_cart_table']} set ct_select = '0' where od_id = '$tmp_cart_id' ";
sql_query($sql);
$fldcnt = count($_POST['it_id']);
for($i=0; $i<$fldcnt; $i++) {
$ct_chk = $_POST['ct_chk'][$i];
if($ct_chk) {
$it_id = $_POST['it_id'][$i];
// 본인인증, 성인인증체크
if(!$is_admin) {
$msg = shop_member_cert_check($it_id, 'item');
if($msg)
alert($msg, G5_SHOP_URL);
}
// 주문 상품의 재고체크
$sql = " select ct_qty, it_name, ct_option, io_id, io_type, ct_reserve, ct_normal
from {$g5['g5_shop_cart_table']}
where od_id = '$tmp_cart_id'
and it_id = '$it_id' ";
$result = sql_query($sql);
for($k=0; $row=sql_fetch_array($result); $k++) {
$sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']}
where od_id <> '$tmp_cart_id'
and it_id = '$it_id'
and io_id = '{$row['io_id']}'
and io_type = '{$row['io_type']}'
and ct_stock_use = 0
and ct_status = '쇼핑'
and ct_select = '1' ";
$sum = sql_fetch($sql);
$sum_qty = $sum['cnt'];
// 재고 구함
$ct_qty = $row['ct_qty'];
if(!$row['io_id'])
$it_stock_qty = get_it_stock_qty($it_id);
else
$it_stock_qty = get_option_stock_qty($it_id, $row['io_id'], $row['io_type']);
if ($ct_qty + $sum_qty > $it_stock_qty)
{
$item_option = $row['it_name'];
if($row['io_id'])
$item_option .= '('.$row['ct_option'].')';
alert($item_option." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개");
}
}
//장바구니 품절
$sql = " select b.it_soldout
from {$g5['g5_shop_cart_table']} a left join {$g5['g5_shop_item_table']} b on ( a.it_id = b.it_id )
where a.od_id = '$tmp_cart_id'
and a.it_id = '$it_id' ";
$res = sql_query($sql);
while ($row=sql_fetch_array($res)){
if ($row['it_soldout'])
{
alert("주문하시려는 상품 중 품절인 상품이 있습니다.");
}
}
// 예약 상품
$sql = " select ct_reserve, ct_normal, it_id
from {$g5['g5_shop_cart_table']}
where od_id = '$tmp_cart_id' ";
$result = sql_query($sql);
while ($row=sql_fetch_array($result)) {
$sql = " select SUM(ct_reserve) as reserve, SUM(ct_normal) as normal
from {$g5['g5_shop_cart_table']}
where od_id = '$tmp_cart_id'
and it_id = '{$row['it_id']}' ";
$sum = sql_fetch($sql);
$tot_reserve+= $sum['reserve'];
$tot_normal+= $sum['normal'];
}
if ( $tot_normal > 0 && $tot_reserve > 0 ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');
$sql = " update {$g5['g5_shop_cart_table']}
set ct_select = '1',
ct_select_time = '".G5_TIME_YMDHIS."'
where od_id = '$tmp_cart_id'
and it_id = '$it_id' ";
sql_query($sql);
}
}
if ($is_member) // 회원인 경우
goto_url(G5_SHOP_URL.'/orderform.php');
else
goto_url(G5_BBS_URL.'/login.php?url='.urlencode(G5_SHOP_URL.'/orderform.php'));
}
!-->!-->
답변 2
체크된값만 가져오는거면 예약상품 쿼리에 and it_id = '$it_id' 다시 넣어야할것같네요
몇번보다니보니 체크된상품에 예약상품 여부를 확인할려고하시는것같은데 굳이 쿼리를 나누기보다는 재고체크할때 같이 들어가도 될것같네요
예약상품이면 ct_reserve = 1 인거죠? 재고검사할때 예약상품인지 체크하고 예약상품이면 $tot_reserve++;로 처리를해줄수있을것같네요
// 주문 상품의 재고체크
$sql = " select ct_qty, it_name, ct_option, io_id, io_type, ct_normal, ct_reserve
from {$g5['g5_shop_cart_table']}
where od_id = '$tmp_cart_id'
and it_id = '$it_id' ";
$result = sql_query($sql);
$tot_reserve = $tot_normal = 0;
for($k=0; $row=sql_fetch_array($result); $k++) {
$sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']}
where od_id <> '$tmp_cart_id'
and it_id = '$it_id'
and io_id = '{$row['io_id']}'
and io_type = '{$row['io_type']}'
and ct_stock_use = 0
and ct_status = '쇼핑'
and ct_select = '1' ";
$sum = sql_fetch($sql);
$sum_qty = $sum['cnt'];
if($row['ct_reserve']) $tot_reserve++;
else if($row['ct_normal']) $tot_normal++;
// 재고 구함
$ct_qty = $row['ct_qty'];
if(!$row['io_id'])
$it_stock_qty = get_it_stock_qty($it_id);
else
$it_stock_qty = get_option_stock_qty($it_id, $row['io_id'], $row['io_type']);
if ($ct_qty + $sum_qty > $it_stock_qty)
{
$item_option = $row['it_name'];
if($row['io_id'])
$item_option .= '('.$row['ct_option'].')';
alert($item_option." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개");
}
}
if ( $tot_normal > 0 && $tot_reserve > 0 ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');
답변을 작성하시기 전에 로그인 해주세요.