0 && $sum_qty < $it['it_buy_min_qty']) alert($it['it_name'].'의 선택옵션 개수 총합 '.number_format($it['it_buy_min_qty']).'개 이상 주문해 주십시오.'); if($it['it_buy_max_qty'] > 0 && $sum_qty > $it['it_buy_max_qty']) alert($it['it_name'].'의 선택옵션 개수 총합 '.number_format($it['it_buy_max_qty']).'개 이하로 주문해 주십시오.'); } // 옵션정보를 얻어서 배열에 저장 $opt_list = array(); $sql = " select * from {$g5['g5_shop_item_option_table']} where it_id = '$it_id' order by io_no asc "; $result = sql_query($sql); $lst_count = 0; for($k=0; $row=sql_fetch_array($result); $k++) { $opt_list[$row['io_type']][$row['io_id']]['id'] = $row['io_id']; $opt_list[$row['io_type']][$row['io_id']]['use'] = $row['io_use']; $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']; $lst_count++; } // 포인트 $point = 0; if($config['cf_use_point']) $point = get_item_point($it); //-------------------------------------------------------- // 재고 검사 //-------------------------------------------------------- // 이미 장바구니에 있는 같은 상품의 수량합계를 구한다. for($k=0; $k<$opt_count; $k++) { $io_id = $_POST['io_id'][$it_id][$k]; $io_type = $_POST['io_type'][$it_id][$k]; $io_value = $_POST['io_value'][$it_id][$k]; $sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']} where it_id = '$it_id' and io_id = '$io_id' and io_type = '$io_type' and ct_stock_use = 0 and ct_status in ('주문', '입금', '준비') "; $row = sql_fetch($sql); $sum_qty = $row['cnt']; // 재고 구함 $ct_qty = $_POST['ct_qty'][$it_id][$k]; if(!$io_id) $it_stock_qty = get_it_stock_qty($it_id); else $it_stock_qty = get_option_stock_qty($it_id, $io_id, $io_type); if ($ct_qty + $sum_qty > $it_stock_qty) { alert($io_value." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty) . " 개"); } } //-------------------------------------------------------- // 바로구매에 있던 장바구니 자료를 지운다. if($i == 0) sql_query(" delete from {$g5['g5_shop_cart_table']} where od_id = '$tmp_cart_id' and ct_direct = 1 ", false); // 옵션수정일 때 기존 장바구니 자료를 먼저 삭제 if($act == 'optionmod') sql_query(" delete from {$g5['g5_shop_cart_table']} where od_id = '$tmp_cart_id' and it_id = '$it_id' "); // 장바구니에 Insert // 바로구매일 경우 장바구니가 체크된것으로 강제 설정 if($sw_direct) $ct_select = 1; else $ct_select = 0; // 장바구니에 Insert $comma = ''; $sql = " INSERT INTO {$g5['g5_shop_cart_table']} ( od_id, mb_id, it_id, it_name, ct_status, ct_price, ct_point, ct_point_use, ct_stock_use, ct_option, ct_qty, ct_notax, io_id, io_type, io_price, ct_time, ct_ip, ct_send_cost, ct_direct, ct_select ) VALUES "; for($k=0; $k<$opt_count; $k++) { $io_id = $_POST['io_id'][$it_id][$k]; $io_type = $_POST['io_type'][$it_id][$k]; $io_value = $_POST['io_value'][$it_id][$k]; // 옵션정보가 존재하는데 선택된 옵션이 없으면 건너뜀 if($lst_count && $io_id == '') continue; // 구매할 수 없는 옵션은 건너뜀 if($io_id && !$opt_list[$io_type][$io_id]['use']) continue; $io_price = $opt_list[$io_type][$io_id]['price']; $ct_qty = $_POST['ct_qty'][$it_id][$k]; // 동일옵션의 상품이 있으면 수량 더함 $sql2 = " select ct_id from {$g5['g5_shop_cart_table']} where od_id = '$tmp_cart_id' and it_id = '$it_id' and io_id = '$io_id' and ct_status = '쇼핑' "; $row2 = sql_fetch($sql2); if($row2['ct_id']) { $sql3 = " update {$g5['g5_shop_cart_table']} set ct_qty = ct_qty + '$ct_qty' where ct_id = '{$row2['ct_id']}' "; sql_query($sql3); continue; } // 배송비결제 if($it['it_sc_type'] > 1 && $it['it_sc_method'] == 1) $ct_send_cost = 1; $sql .= $comma."( '$tmp_cart_id', '{$member['mb_id']}', '{$it['it_id']}', '{$it['it_name']}', '쇼핑', '{$it['it_price']}', '$point', '0', '0', '$io_value', '$ct_qty', '{$it['it_notax']}', '$io_id', '$io_type', '$io_price', '".G5_TIME_YMDHIS."', '$REMOTE_ADDR', '$ct_send_cost', '$sw_direct', '$ct_select' )"; $comma = ' , '; $ct_count++; } if($ct_count > 0) sql_query($sql); } } // 바로 구매일 경우 if ($sw_direct) { if ($is_member) { goto_url(G5_SHOP_URL."/orderform.php?sw_direct=$sw_direct"); } else { goto_url(G5_BBS_URL."/login.php?url=".urlencode(G5_SHOP_URL."/orderform.php?sw_direct=$sw_direct")); } } else { goto_url(G5_SHOP_URL.'/cart.php'); } ?>