diff --git a/js/shop.js b/js/shop.js new file mode 100644 index 000000000..e54a22459 --- /dev/null +++ b/js/shop.js @@ -0,0 +1,5 @@ +// php chr() 대응 +function chr(code) +{ + return String.fromCharCode(code); +} \ No newline at end of file diff --git a/lib/shop.lib.php b/lib/shop.lib.php index 343a6f1a4..7403a2ce8 100644 --- a/lib/shop.lib.php +++ b/lib/shop.lib.php @@ -502,43 +502,123 @@ function session_check() gotourl(G4_SHOP_URL); } -// 상품 옵션 -function get_item_options($subject, $option, $index) +// 상품 선택옵션 +function get_item_options($it_id, $subject) { - $subject = trim($subject); - $option = trim($option); + global $g4; - if (!$subject || !$option) return ''; + if(!$it_id || !$subject) + return ''; + + $sql = " select * from {$g4['shop_item_option_table']} where io_type = '0' and it_id = '$it_id' and io_use = '1' order by io_no asc "; + $result = sql_query($sql); + if(!mysql_num_rows($result)) + return ''; $str = ''; + $subj = explode(',', $subject); + $subj_count = count($subj); + $options = array(); - $arr = explode("\n", $option); - // 옵션이 하나일 경우 - if (count($arr) == 1) - { - $str = ''; + // 옵션항목 배열에 저장 + for($i=0; $row=sql_fetch_array($result); $i++) { + $opt_id = explode(chr(30), $row['io_id']); + + for($k=0; $k<$subj_count; $k++) { + if(!is_array($options[$k])) + $options[$k] = array(); + + if($opt_id[$k] && !in_array($opt_id[$k], $options[$k])) + $options[$k][] = $opt_id[$k]; + } } - else - { - $str = ''.PHP_EOL; + $select .= ''.PHP_EOL; + for($k=0; $k<$opt_count; $k++) { + $opt_val = $opt[$k]; + if($opt_val) { + $select .= ''.PHP_EOL; + } } - $str .= ''.PHP_EOL; + $select .= ''.PHP_EOL; + + $str .= ''.$select.''.PHP_EOL; + $str .= ''.PHP_EOL; + } + } + + return $str; +} + +// 상품 추가옵션 +function get_item_supply($it_id, $subject) +{ + global $g4; + + if(!$it_id || !$subject) + return ''; + + $sql = " select * from {$g4['shop_item_option_table']} where io_type = '1' and it_id = '$it_id' and io_use = '1' order by io_no asc "; + $result = sql_query($sql); + if(!mysql_num_rows($result)) + return ''; + + $str = ''; + $str .= ''.PHP_EOL; + $str .= '추가상품'.PHP_EOL; + $str .= '추가구매를 원하시면 선택하세요.'.PHP_EOL; + $str .= ''.PHP_EOL; + + $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($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]; + } + + // 옵션항목 만들기 + for($i=0; $i<$subj_count; $i++) { + $opt = $options[$subj[$i]]; + $opt_count = count($opt); + if($opt_count) { + $seq = $i + 1; + $str .= ''.PHP_EOL; + $str .= ''.PHP_EOL; + + $select = ''.PHP_EOL; + + $str .= ''.$select.''.PHP_EOL; + $str .= ''.PHP_EOL; } - $str .= ''.PHP_EOL.''.PHP_EOL; } return $str; diff --git a/shop/item.php b/shop/item.php index cac9d9147..1ca2fc2e4 100644 --- a/shop/item.php +++ b/shop/item.php @@ -273,22 +273,6 @@ else - '.PHP_EOL; - echo ''.PHP_EOL; - echo ''.$str.''.PHP_EOL; - echo ''.PHP_EOL; - } - } - ?> - @@ -334,6 +318,14 @@ else + + + + 수량