From 24b07b2cf2007241cd0e37fcd25ccea593603178 Mon Sep 17 00:00:00 2001 From: chicpro Date: Thu, 23 May 2013 13:56:15 +0900 Subject: [PATCH] =?UTF-8?q?#176=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D,=EC=B6=94=EA=B0=80=20=EC=98=B5=EC=85=98=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EC=9E=91=EC=97=85=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/shop.js | 5 ++ lib/shop.lib.php | 138 +++++++++++++++++++++++++++++++++++++---------- shop/item.php | 24 +++------ 3 files changed, 122 insertions(+), 45 deletions(-) create mode 100644 js/shop.js 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 + + + + 수량