선택옵션을 4개로 늘리고 저장하면 데이터가 삭제되는 현상

선택옵션을 4개로 늘리고 저장하면 데이터가 삭제되는 현상

QA

선택옵션을 4개로 늘리고 저장하면 데이터가 삭제되는 현상

본문

선택옵션(필수)을 기존 3개 고정에서 1개 추가해서 4개로 늘려놓은 상태입니다.

 

옵션1에 8개( ex. a,b,c,d,e,f,g,h )

옵션2에 8개( ex. a,b,c,d,e,f,g,h )

옵션3에 8개( ex. a,b,c,d,e,f,g,h )

옵션4에 8개( ex. ㄱ,ㄴ,ㄷ,ㄹ,ㅁ,ㅂ,ㅅ,ㅇ ).... 라고 가정해도 경우의 수가 너무 많아지기는 하는데

 

일단 이슈가...

 

옵션목록생성하면 리스트는 잘 뜨는데

 

옵션 목록 잘 뜨는거 확인한 후에 저장하고 보면

 

옵션1에 a~h까지 남아있어야하는데 a만 남고 나머지는 다 지워진채로 뜨고,

옵션2도 a~h까지 남아있어야하는데 h만 지워진채로 a~g까지 뜨고,

옵션3, 옵션4만 원래대로 남아있습니다. 출력된 목록은 다행히 틀어지진 않습니다...;;

 

근데 상품 상세페이지 가보면... 옵션1 에 선택할 수 있는게 a만 뜨고,

옵션2는 a~g까지 뜨고.... 옵션목록생성 했을때 나온 리스트대로 뜨질 않습니다.

 

너무 경우의 수가 많아져서 이러는 걸까요...??

이 질문에 댓글 쓰기 :

답변 4

저장되는 시점을 echo로 찍어서 확인해보셔야할거같은데요

값을 못받아오는건지 아니면 사라지는건지 일일히 찾아봐야겠네요

경우의 수가 너무 많아서일까요...??ㅠ

일단 옵션은... 경우의수를 따져서 700개가 넘어가면 옵션1 만 데이터가 한개 날아가네요;;

옵션1~3 4개
옵션4 12개

4*4*4*12 하면 768의 경우의 수인데 옵션으로 만들 수 있는 경우의 수는 500 미만으로 생성해야 그나마 옵션이 다 살거 같습니다.


db에 저장도 안되고 있던거였어요;;

db에 저장된건 393개정도 였고...

8*8*8*12 하면 4096 이라는 경우의 수가 나오는데;;

393개만 저장된거면 맥시멈이 393 이라고 봐도 될 것 같네요;;ㅠ

답변 감사드립니다~!

목록을 하드코딩해둔게 아니라 코드로 불러오는건가요?

소스를 보여주셔야 정확히 알거같네요

/shop_admin/itemform.php


<!-- 상품선택옵션 테이블 옵션4 추가 -->
<tr>
    <th scope="row">
        <label for="opt4_subject">옵션4</label>
        <input type="text" name="opt4_subject" value="<?php echo $opt_subject[3]; ?>" id="opt4_subject" class="frm_input" size="15">
    </th>
    <td>
        <label for="opt4"><b>옵션4 항목</b></label>
        <input type="text" name="opt4" value="" id="opt4" class="frm_input" size="50">
    </td>
</tr>
 
 
<!-- 옵션항목설정 스크립트 옵션4 추가 -->
<script>
<?php if($it['it_id'] && $po_run) { ?>
//옵션항목설정
var arr_opt1 = new Array();
var arr_opt2 = new Array();
var arr_opt3 = new Array();
var arr_opt4 = new Array(); // 옵션4 관련 추가
var opt1 = opt2 = opt3 = opt4 = ''; // 옵션4 관련 추가
var opt_val;
$(".opt-cell").each(function() {
    opt_val = $(this).text().split(" > ");
    opt1 = opt_val[0];
    opt2 = opt_val[1];
    opt3 = opt_val[2];
    opt4 = opt_val[3]; // 옵션4 관련 추가
    if(opt1 && $.inArray(opt1, arr_opt1) == -1)
        arr_opt1.push(opt1);
    if(opt2 && $.inArray(opt2, arr_opt2) == -1)
        arr_opt2.push(opt2);
    if(opt3 && $.inArray(opt3, arr_opt3) == -1)
        arr_opt3.push(opt3);
    if(opt4 && $.inArray(opt4, arr_opt4) == -1) // 옵션4 관련 추가
        arr_opt4.push(opt4);
});

$("input[name=opt1]").val(arr_opt1.join());
$("input[name=opt2]").val(arr_opt2.join());
$("input[name=opt3]").val(arr_opt3.join());
$("input[name=opt4]").val(arr_opt4.join()); // 옵션4 관련 추가
<?php } ?>
// 옵션목록생성
$("#option_table_create").click(function() {
    var it_id = $.trim($("input[name=it_id]").val());
    var opt1_subject = $.trim($("#opt1_subject").val());
    var opt2_subject = $.trim($("#opt2_subject").val());
    var opt3_subject = $.trim($("#opt3_subject").val());
    var opt4_subject = $.trim($("#opt4_subject").val()); // 옵션4 관련 추가
    var opt1 = $.trim($("#opt1").val());
    var opt2 = $.trim($("#opt2").val());
    var opt3 = $.trim($("#opt3").val());
    var opt4 = $.trim($("#opt4").val()); // 옵션4 관련 추가
    var $option_table = $("#sit_option_frm");
    if(!opt1_subject || !opt1) {
        alert("옵션명과 옵션항목을 입력해 주십시오.");
        return false;
    }
    $.post(
        "<?php echo G5_ADMIN_URL; ?>/shop_admin/itemoption.php",
        { it_id: it_id, w: "<?php echo $w; ?>", opt1_subject: opt1_subject, opt2_subject: opt2_subject, opt3_subject: opt3_subject, opt4_subject: opt4_subject, opt1: opt1, opt2: opt2, opt3: opt3, opt4: opt4 }, // 옵션4 관련 추가
        function(data) {
            $option_table.empty().html(data);
        }
    );
});
</script>

 

 

/shop_admin/itemformupdate.php


// 선택옵션
sql_query(" delete from {$g5['g5_shop_item_option_table']} where io_type = '0' and it_id = '$it_id' "); // 기존선택옵션삭제
$option_count = (isset($_POST['opt_id']) && is_array($_POST['opt_id'])) ? count($_POST['opt_id']) : array();
if($option_count) {
    // 옵션명
    $opt1_cnt = $opt2_cnt = $opt3_cnt = $opt4_cnt = 0; // 옵션4 관련 추가
    for($i=0; $i<$option_count; $i++) {
        $_POST['opt_id'][$i] = preg_replace(G5_OPTION_ID_FILTER, '', $_POST['opt_id'][$i]);
        $opt_val = explode(chr(30), $_POST['opt_id'][$i]);
        if($opt_val[0])
            $opt1_cnt++;
        if($opt_val[1])
            $opt2_cnt++;
        if($opt_val[2])
            $opt3_cnt++;
        if($opt_val[3]) // 옵션4 관련 추가
            $opt4_cnt++;
    }
    if($opt1_subject && $opt1_cnt) {
        $it_option_subject = $opt1_subject;
        if($opt2_subject && $opt2_cnt)
            $it_option_subject .= ','.$opt2_subject;
        if($opt3_subject && $opt3_cnt)
            $it_option_subject .= ','.$opt3_subject;
        if($opt4_subject && $opt4_cnt) // 옵션4 관련 추가
            $it_option_subject .= ','.$opt4_subject;
    }
}

 

/shop_admin/itemoption.php


<!-- 상단 개발 부분 -->
<?php
$po_run = false;
if($it['it_id']) {
    $opt_subject = explode(',', $it['it_option_subject']);
    $opt1_subject = $opt_subject[0];
    $opt2_subject = $opt_subject[1];
    $opt3_subject = $opt_subject[2];
    $opt4_subject = $opt_subject[3]; // 옵션4 관련 추가
 
    $sql = " select * from {$g5['g5_shop_item_option_table']} where io_type = '0' and it_id = '{$it['it_id']}' order by io_no asc ";
    $result = sql_query($sql);
    if(sql_num_rows($result))
        $po_run = true;
} else if(!empty($_POST)) {
    $opt1_subject = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['opt1_subject'])));
    $opt2_subject = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['opt2_subject'])));
    $opt3_subject = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['opt3_subject'])));
    $opt4_subject = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['opt4_subject']))); // 옵션4 관련 추가
 
    $opt1_val = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['opt1'])));
    $opt2_val = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['opt2'])));
    $opt3_val = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['opt3'])));
    $opt4_val = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['opt4']))); // 옵션4 관련 추가
 
    if(!$opt1_subject || !$opt1_val) {
        echo '옵션1과 옵션1 항목을 입력해 주십시오.';
        exit;
    }
    $po_run = true;
    $opt1_count = $opt2_count = $opt3_count = $opt4_count = 0;
    if($opt1_val) {
        $opt1 = explode(',', $opt1_val);
        $opt1_count = count($opt1);
    }
    if($opt2_val) {
        $opt2 = explode(',', $opt2_val);
        $opt2_count = count($opt2);
    }
    if($opt3_val) {
        $opt3 = explode(',', $opt3_val);
        $opt3_count = count($opt3);
    }
    if($opt4_val) { // 옵션4 관련 추가
        $opt4 = explode(',', $opt4_val);
        $opt4_count = count($opt4);
    }
}
if($po_run) {
?>
 
 
<!-- tbody 내 if($it['it_id']) 부분 -->
<tbody>
<?php
if($it['it_id']) {
    for($i=0; $row=sql_fetch_array($result); $i++) {
        $opt_id = $row['io_id'];
        $opt_val = explode(chr(30), $opt_id);
        $opt_1 = $opt_val[0];
        $opt_2 = $opt_val[1];
        $opt_3 = $opt_val[2];
        $opt_4 = $opt_val[3]; // 옵션4 관련 추가

        $opt_2_len = strlen($opt_2);
        $opt_3_len = strlen($opt_3);
        $opt_4_len = strlen($opt_4); // 옵션4 관련 추가

        $opt_price = $row['io_price'];
        $opt_stock_qty = $row['io_stock_qty'];
        $opt_noti_qty = $row['io_noti_qty'];
        $opt_use = $row['io_use'];
?>
<tr>
    <td class="td_chk">
        <input type="hidden" name="opt_id[]" value="<?php echo $opt_id; ?>">
        <label for="opt_chk_<?php echo $i; ?>" class="sound_only"></label>
        <input type="checkbox" name="opt_chk[]" id="opt_chk_<?php echo $i; ?>" value="1">
    </td>
    <td class="opt-cell"><?php echo $opt_1; if ($opt_2_len) echo ' <small>></small> '.$opt_2; if ($opt_3_len) echo ' <small>></small> '.$opt_3; if ($opt_4_len) echo ' <small>></small> '.$opt_4; // 옵션4 관련 추가 ?></td>
 
 
<!-- tbody 내 else 부분 --> 
<?php
} else {
    for($i=0; $i<$opt1_count; $i++) {
        $j = 0;
        do {
            $k = 0;
            do {
                $l = 0; // 옵션4 관련 추가
                do{ // 옵션4 관련 추가
                    $opt_1 = strip_tags(trim($opt1[$i]));
                    $opt_2 = strip_tags(trim($opt2[$j]));
                    $opt_3 = strip_tags(trim($opt3[$k]));
                    $opt_4 = strip_tags(trim($opt4[$l])); // 옵션4 관련 추가
 
                    $opt_2_len = strlen($opt_2);
                    $opt_3_len = strlen($opt_3);
                    $opt_4_len = strlen($opt_4); // 옵션4 관련 추가
 
                    $opt_id = $opt_1;
                    if($opt_2_len)
                        $opt_id .= chr(30).$opt_2;
                    if($opt_3_len)
                        $opt_id .= chr(30).$opt_3;
                    if($opt_4_len) // 옵션4 관련 추가
                        $opt_id .= chr(30).$opt_4;

                    $opt_price = 0;
                    $opt_stock_qty = 9999;
                    $opt_noti_qty = 100;
                    $opt_use = 1;
                    // 기존에 설정된 값이 있는지 체크
                    if($_POST['w'] == 'u') {
                        $sql = " select io_price, io_stock_qty, io_noti_qty, io_use
                                    from {$g5['g5_shop_item_option_table']}
                                    where it_id = '{$_POST['it_id']}'
                                      and io_id = '$opt_id'
                                      and io_type = '0' ";
                        $row = sql_fetch($sql);
                        if($row) {
                            $opt_price = (int)$row['io_price'];
                            $opt_stock_qty = (int)$row['io_stock_qty'];
                            $opt_noti_qty = (int)$row['io_noti_qty'];
                            $opt_use = (int)$row['io_use'];
                        }
                    }
?>
<tr>
    <td class="td_chk">
        <input type="hidden" name="opt_id[]" value="<?php echo $opt_id; ?>">
        <label for="opt_chk_<?php echo $i; ?>" class="sound_only"></label>
        <input type="checkbox" name="opt_chk[]" id="opt_chk_<?php echo $i; ?>" value="1">
    </td>
    <td class="opt1-cell"><?php echo $opt_1; if ($opt_2_len) echo ' <small>></small> '.$opt_2; if ($opt_3_len) echo ' <small>></small> '.$opt_3; if ($opt_4_len) echo ' <small>></small> '.$opt_4; // 옵션4 관련 추가 ?></td>

 

 

 

이렇게 추가해놓은 상태 입니다ㅠ

짤리는 옵션1,옵션2가 혹시 내용이 길지않나요?

옵션3,옵션4는 출력된다는거보니

저장될때 데이터유형에 맞는 허용치를 넘긴것같아서 짤리는것같아요

제가 기억이안나는데 영카트의 옵션부분에 데이터유형이 어떻게 되는지 모르겠네요

아마 DB확인하셔서 보시면 데이터값이 짤려있으면 데이터유형을 변경해주셔야 할것같아요

옵션1~3에 들어가는 옵션명+옵션개수(?)가 동일합니다...

1~3 은 컬러값들이 들어갈 예정이구요;;

Red,Orange,Yellow,Green,Blue,Black,White,Darkgray

이런식으로 컬러값들이 옵션1~3 모두 동일하게 들어갈 예정입니다.

옵션명은 바뀔수도 있어서 예시고, 지금 저 옵션명들로 생성해놓았는데...

옵션명출력까지는 잘 뜨는데 저장하면 데이터가 날라가고 있는 상태입니다ㅠㅠㅠ

답변을 작성하시기 전에 로그인 해주세요.
전체 123,123 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT