#176 사용자 선택,추가 옵션 출력 작업 중

This commit is contained in:
chicpro
2013-05-23 13:56:15 +09:00
parent ef08088fa1
commit 24b07b2cf2
3 changed files with 124 additions and 47 deletions

5
js/shop.js Normal file
View File

@ -0,0 +1,5 @@
// php chr() 대응
function chr(code)
{
return String.fromCharCode(code);
}

View File

@ -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 = '<input type="text" value='.$option.' id="sit_opt_'.$index.'" readonly class="sit_ov_opt">';
}
else
{
$str = '<select name="it_opt'.$index.'" id="sit_opt_'.$index.'" onchange="amount_change()">'.PHP_EOL;
for ($k=0; $k<count($arr); $k++)
{
$arr[$k] = str_replace("\r", "", $arr[$k]);
$opt = explode(";", trim($arr[$k]));
$str .= '<option value="'.$arr[$k].'">'.$opt[0].'</option>';
// 옵션에 금액이 있다면
if ($opt[1] != 0)
{
$str .= ' (';
// - 금액이 아니라면 모두 + 금액으로
//if (!ereg("[-]", $opt[1]))
if (!preg_match("/[-]/", $opt[1]))
$str .= '+';
$str .= display_price($opt[1]) . ')';
}
$str .= '</option>'.PHP_EOL;
// 옵션항목 배열에 저장
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];
}
}
// 옵션선택목록 만들기
for($i=0; $i<$subj_count; $i++) {
$opt = $options[$i];
$opt_count = count($opt);
$disabled = '';
if($opt_count) {
$seq = $i + 1;
if($i > 0)
$disabled = ' disabled="disabled"';
$str .= '<tr>'.PHP_EOL;
$str .= '<th><label for="it_option_'.$seq.'">'.$subj[$i].'</label></th>'.PHP_EOL;
$select = '<select name="it_option[]" id="it_option_'.$seq.'"'.$disabled.'>'.PHP_EOL;
$select .= '<option value="">선택</option>'.PHP_EOL;
for($k=0; $k<$opt_count; $k++) {
$opt_val = $opt[$k];
if($opt_val) {
$select .= '<option value="'.$opt_val.'">'.$opt_val.'</option>'.PHP_EOL;
}
}
$select .= '</select>'.PHP_EOL;
$str .= '<td>'.$select.'</td>'.PHP_EOL;
$str .= '</tr>'.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 .= '<tr>'.PHP_EOL;
$str .= '<th>추가상품</th>'.PHP_EOL;
$str .= '<td>추가구매를 원하시면 선택하세요.</td>'.PHP_EOL;
$str .= '</tr>'.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 .= '<tr>'.PHP_EOL;
$str .= '<th><label for="it_supply_'.$seq.'">'.$subj[$i].'</label></th>'.PHP_EOL;
$select = '<select name="it_supply[]" id="it_supply_'.$seq.'">'.PHP_EOL;
$select .= '<option value="">선택</option>'.PHP_EOL;
for($k=0; $k<$opt_count; $k++) {
$opt_val = $opt[$k];
if($opt_val) {
$select .= '<option value="'.$opt_val.'">'.$opt_val.'</option>'.PHP_EOL;
}
}
$select .= '</select>'.PHP_EOL;
$str .= '<td>'.$select.'</td>'.PHP_EOL;
$str .= '</tr>'.PHP_EOL;
}
$str .= '</select>'.PHP_EOL.'<input type="hidden" name="it_opt'.$index.'_subject" value="'.$subject.'">'.PHP_EOL;
}
return $str;

View File

@ -273,22 +273,6 @@ else
</tr>
<?php } ?>
<?php
// 선택옵션 출력
for ($i=1; $i<=6; $i++)
{
// 옵션에 문자가 존재한다면
$str = get_item_options(trim($it['it_opt'.$i.'_subject']), trim($it['it_opt'.$i]), $i);
if ($str)
{
echo '<tr>'.PHP_EOL;
echo '<th scope="row"><label for="sit_opt_'.$i.'">'.$it['it_opt'.$i.'_subject'].'</label></th>'.PHP_EOL;
echo '<td style="word-break:break-all;">'.$str.'</td>'.PHP_EOL;
echo '</tr>'.PHP_EOL;
}
}
?>
<?php if (!$it['it_gallery']) { // 갤러리 형식이라면 가격, 구매하기 출력하지 않음 ?>
<?php if ($it['it_tel_inq']) { // 전화문의일 경우 ?>
@ -334,6 +318,14 @@ else
</tr>
<?php } ?>
<?php // 선택옵션
echo get_item_options($it['it_id'], $it['it_option_subject']);
?>
<?php // 추가옵션
echo get_item_supply($it['it_id'], $it['it_supply_subject']);
?>
<tr>
<th scope="row">수량</th>
<td>