테스트 사이트 - 개발 중인 베타 버전입니다

상품에 선택옵션 추가시 장바구니에 안담아져서 질문좀 드립니다.(소스있음) 채택완료

경하귀요밍 8년 전 조회 4,031

안녕하세요..!!

이전 개발자가 개발한것을 수정중인데..

상품에 선택옵션이 없을때는 장바구니에 잘들어가는데 선택옵션을 추가하면 장바구니에 담아지지 않습니다..ㅜㅜ 오류도 안생기구요.. 

<?php include("_common.php")?> 같은 header 및 tail 부분은 생략했습니다.

 

shop/cart.php

<!-- 장바구니 시작 { -->

<script src="<?php echo G5_JS_URL; ?>/shop.js"></script>

<section class="cart">

    <h1>cart</h1>

    <section class="cart_box">

<form name="frmcartlist" id="sod_bsk_list" method="post" action="<?php echo $cart_action_url; ?>">

<?php

$tot_point = 0;

$tot_sell_price = 0;

 

// $s_cart_id 로 현재 장바구니 자료 쿼리

$sql = " select a.ct_id, a.it_id, a.it_name, a.ct_price, a.ct_point, a.ct_qty, a.ct_status, a.ct_send_cost, a.it_sc_type,

b.ca_id, b.ca_id2, b.ca_id3, b.it_cust_price

from {$g5['g5_shop_cart_table']} a left join {$g5['g5_shop_item_table']} b on ( a.it_id = b.it_id )

where a.od_id = '$s_cart_id' ";

$sql .= " group by a.it_id ";

$sql .= " order by a.ct_id ";

$result = sql_query($sql);

 

$it_send_cost = 0;

 

for ($i=0; $row=sql_fetch_array($result); $i++) {

// 합계금액 계산

$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,

SUM(ct_point * ct_qty) as point,

SUM(ct_qty) as qty

from {$g5['g5_shop_cart_table']}

where it_id = '{$row['it_id']}'

 and od_id = '$s_cart_id' ";

$sum = sql_fetch($sql);

 

if ($i==0) { // 계속쇼핑

$continue_ca_id = $row['ca_id'];

}

$a1 = '<a href="./item.php?it_id='.$row['it_id'].'">';

$a2 = '</a>';

$image = $a1 .get_it_image_random($row['it_id'], 0, 70). $a2;

$it_name = stripslashes($row['it_name']);

 

// 배송비

...

// 조건부무료

...

$point      = $sum['point'];

$sell_price = $sum['price'];

$cust_price = $row['it_cust_price']*$row['ct_qty'];

?>

<article class="cart_item">

<input type="hidden" name="it_id[<?php echo $i; ?>]"    value="<?php echo $row['it_id']; ?>">

<input type="hidden" name="it_name[<?php echo $i; ?>]"  value="<?php echo get_text($row['it_name']); ?>">

  <input type="hidden" name="ct_chk[<?php echo $i; ?>]" value="1" id="ct_chk_<?php echo $i; ?>" style="display:none;">

<div class="cart_thumb"><?php echo $image; ?></div>

<div class="cart_info">

<span class="cart_t"><?php echo $it_name; ?> <?php echo number_format($sum['qty']); ?> <span class="font_na">개</span></span>

<span class="cart_p"><?php echo number_format($cust_price); ?>원 → <strong><?php echo number_format($sell_price); ?>원</strong></span>

<span class="cart_num">

<b><?php echo number_format($sum['qty']); ?></b> items

</span>

<span class="cart_go gray"><a href="<?php echo $i; ?>" class="item_modify_btn" >modify</a>&nbsp;&nbsp;<a href="<?php echo $i; ?>" class="item_del_btn" >del</a></span>

</div>

</article>

<?php

$tot_point      += $point;

$tot_sell_price += $sell_price;

} // for 끝

if ($i == 0) {

echo '<article class="no_item">장바구니에 제품이 없습니다.</article>';

} else {

// 배송비 계산

$send_cost = get_sendcost($s_cart_id, 0);

}

?>

<?php

$tot_price = $tot_sell_price + $send_cost; // 총계 = 주문상품금액합계 + 배송비

if ($tot_price > 0 || $send_cost > 0) {

?>

<article class="count">

<dl>

<dt>총 상품금액</dt>

<dd class="count_price"><?php echo number_format($tot_sell_price); ?>원</dd>

<dt>배송비</dt>

<dd class="count_price"><?php echo number_format($send_cost); ?>원</dd>

</dl>

</article>

<?php

if ($tot_price > 0) {

?>

<article class="count2">

<div class="cart_comment">배송비 2,500원(3만원이상 무료), 장바구니에 담아서 한꺼번에 구매하세요.</div>

<dl>

<dt>총 주문금액</dt>

<dd class="count_price2"><?php echo number_format($tot_price); ?>원</dd>

</dl>

</article>

<?php } ?>

<?php } ?>

<div class="btn_box white">

<?php if ($i == 0) { ?>

<?php } else { ?>

<input type="hidden" name="url" value="./orderform.php">

<input type="hidden" name="records" value="<?php echo $i; ?>">

<input type="hidden" name="act" value="">

<a href="#" id="item_buy_btn"><div class="btn_gold">buy</div></a>

<?php } ?>

</div>

</form>

    </section>

</section>

<script>

$(function() {

    var close_btn_idx;    

     // 수량변경 DESIGNYEON

     $(document).on("click", "#sit_qty_plus_design", function(e) {

        e.preventDefault();

        var this_qty, max_qty = 9999, min_qty = 1;

        var $el_qty = $(this).parent().parent().find("input[name^=ct_qty]");

        var stock = parseInt($(this).parent().parent().find("input.io_stock").val());

 

        this_qty = parseInt($el_qty.val().replace(/[^0-9]/, "")) + 1;

         console.log(this_qty);

        if(this_qty > stock) {

            alert("재고수량 보다 많은 수량을 구매할 수 없습니다.");

            this_qty = stock;

        }

        if(this_qty > max_qty) {

            this_qty = max_qty;

            alert("최대 구매수량은 "+number_format(String(max_qty))+" 입니다.");

        }

        $el_qty.val(this_qty);

        price_calculate();

        $('#sit_tot_price').hide();

     });

    // 수량변경 DESIGNYEON

     $(document).on("click", "#sit_qty_minus_design", function(e) {

        e.preventDefault();

        var this_qty, max_qty = 9999, min_qty = 1;

        var $el_qty = $(this).parent().parent().find("input[name^=ct_qty]");

        var stock = parseInt($(this).parent().parent().find("input.io_stock").val());

 

        this_qty = parseInt($el_qty.val().replace(/[^0-9]/, "")) - 1;

        if(this_qty < min_qty) {

            this_qty = min_qty;

            alert("최소 구매수량은 "+number_format(String(min_qty))+" 입니다.");

        }

        $el_qty.val(this_qty);

        price_calculate();

        $('#sit_tot_price').hide();

     });

    // 옵션수정 닫기 DESIGNYEON

    $(document).on("click", "#mod_option_close_design", function(e) {

        e.preventDefault();

        $("#mod_option_frm_market").remove();

        $(".mod_options").eq(close_btn_idx).focus();

    });

    // 선택사항수정

    $(".mod_options").click(function() {

        var it_id = $(this).closest("tr").find("input[name^=it_id]").val();

        var $this = $(this);

        close_btn_idx = $(".mod_options").index($(this));

 

        $.post(

            "./cartoption_designyeon.php",

            { it_id: it_id },

            function(data) {

                $("#itme_cnt_input_area_").remove();

                $this.after("<div id=\"mod_option_frm_market\"></div>");

                $("#mod_option_frm_market").html(data);

                price_calculate();

            }

        );

    });

    // 모두선택

    $("input[name=ct_all]").click(function() {

        if($(this).is(":checked"))

            $("input[name^=ct_chk]").attr("checked", true);

        else

            $("input[name^=ct_chk]").attr("checked", false);

    });

    // 옵션수정 닫기

    $(document).on("click", "#mod_option_close", function() {

        $("#mod_option_frm_market").remove();

        $(".mod_options").eq(close_btn_idx).focus();

    });

    $("#win_mask").click(function () {

        $("#mod_option_frm_market").remove();

        $(".mod_options").eq(close_btn_idx).focus();

    });

// 수정 버튼

    $(".item_modify_btn").bind("click", function(event){

event.preventDefault();

        var num = $(this).attr("href");

var it_id = $(this).closest("article").find("input[name^=it_id]").val();

        var $this = $(this);

//$(this).parent().parent().find(".cart_num").empty();

        $.post(

            "./cartoption_designyeon.php",

            { it_id: it_id },

            function(data) {

$("#mod_option_frm_market").remove();

                $this.parent().parent().after("<div id=\"mod_option_frm_market\" class=\"cart_modify_open\" ></div>");

                $("#mod_option_frm_market").html(data);

                price_calculate();

                $('#sit_tot_price').hide();

            }

        );

return true;

    });

// 삭제 버튼

    $(".item_del_btn").bind("click", function(event){

event.preventDefault();

        var num = $(this).attr("href");

$("input[name^=ct_chk]").val(0);

$("input[name^=ct_chk]").eq(num).val(1);

form_check("seldelete")

return true;

    });

// 구매 버튼

    $("#item_buy_btn").bind("click", function(event){

event.preventDefault();

form_check('buy');

return true;

    });

});

function del_check(num){

$("input[name^=ct_chk]").val(0);

$("input[name^=ct_chk]").eq(num).val(1);

form_check("seldelete");

}

function form_check(act) {

    var f = document.frmcartlist;

    var cnt = f.records.value;

    if (act == "buy")

    {

        f.act.value = act;

        f.submit();

    }

else if (act == "seldelete")

    {

        f.act.value = act;

        f.submit();

    }

    return true;

}

</script>

 

/skin/shop/basic/list.form.skin.php 

<?php

if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

?>

<form name="fitem" id="fitem" method="post" action="<?php echo $action_url; ?>" onsubmit="return fitem_submit(this);">

<input type="hidden" name="it_id[]" value="<?php echo $it_id; ?>">

<input type="hidden" name="sw_direct">

<input type="hidden" name="url">

<section class="detail">

<!-- 상품이미지 미리보기 시작 { -->    

<article class="pro_detail_img">

<?php

$big_img_count = 0;

$thumbnails = array();

$img = get_it_thumbnail_no($it['it_img3'], 571, 571);

 

if($img) {

// 썸네일

$thumb = get_it_thumbnail_no($it['it_img3'.$i], 571, 571);

$thumbnails[] = $thumb;

$big_img_count++;

//echo '<a href="'.G5_SHOP_URL.'/largeimage.php?it_id='.$it['it_id'].'&amp;no='.$i.'" target="_blank" class="popup_item_image">'.$img.'</a>';

echo ''.$img.'';

}

if($big_img_count == 0) { 

echo '<img src="'.G5_SHOP_URL.'/img/no_image.gif" alt="">';

}

?>

</article>

<!-- } 상품이미지 미리보기 끝 -->

<article class="pro_detail_info">

<div class="p_d_h1"><?php echo stripslashes($it['it_name']); ?></div>

<div class="p_d_h2"><?php echo $it['it_basic']; ?></div>

<div class="p_d_price">

<span class="price_sale"><?php echo number_format($it['it_cust_price'],0); ?> won</span> 

<?php echo number_format(get_price($it),0); ?> won 

<input type="hidden" id="it_price" value="<?php echo get_price($it); ?>">

</div>

<?php if ($is_orderable) { ?>

<!-- 총 구매액 -->

<div id="sit_tot_price"></div>

<?php } ?>

 

<?php if($is_soldout) { ?>

<p id="sit_ov_soldout">상품의 재고가 부족하여 구매할 수 없습니다.</p>

<?php } ?>

<div class="p_d_option" id="item_info_area">

<?php

if(!$it['it_buy_min_qty'])

$it['it_buy_min_qty'] = 1;

?>

<input type="hidden" name="io_type[<?php echo $it_id; ?>][]" value="0">

<input type="hidden" name="io_id[<?php echo $it_id; ?>][]" value="">

<input type="hidden" name="io_value[<?php echo $it_id; ?>][]" value="<?php echo $it['it_name']; ?>">

<input type="hidden" class="io_price" value="0">

<input type="hidden" class="io_stock" value="<?php echo $it['it_stock_qty']; ?>">

              <div class="count_btn_up"><a href="#" id="item_add_btn" ><img src="<?php echo G5_THEME_URL ?>/images/count_up.png" width="24px"></a></div>

<div class="count_btn_down"><a href="#" id="item_minus_btn"><img src="<?php echo G5_THEME_URL ?>/images/count_down.png" width="24px"></a></div>

<input type="text" class="frm_input count_input" name="ct_qty[<?php echo $it_id; ?>][]" value="<?php echo $it['it_buy_min_qty']; ?>" id="ct_qty_<?php echo $i; ?>" >

<?php

        if($option_item) {

        ?>

        <!-- 선택옵션 시작 { -->

            <?php // 선택옵션

            echo $option_item;

            ?>

        <!-- } 선택옵션 끝 -->

        <?php

        }

        ?>

</div>

<div class="p_d_btn white">

<a href="#" id="add_cart_btn" ><div class="btn_gold">add to cart</div></a>

</div>

 

<div class="p_d_comment aaa">대량 구매 문의 시 <a href="<?php echo G5_BBS_URL; ?>/qalist.php"><u>1:1 comment</u></a> 를 이용해주세요.<br>배송, 교환 환불 시 <a href="<?php echo G5_BBS_URL; ?>/board.php?bo_table=notice"><u>notice</u></a>을 확인해주세요.</div>

<div class="p_d_page aaa">

<span><a href="<?php echo G5_URL; ?>">list</a></span>

<!-- 다른 상품 보기 시작 { -->

<?php

if ($prev_href) {

echo '<span>'.$prev_href.'pre'.$prev_href2.'</span>';

}else{

echo '<span style="opacity:0.5">pre</span>';

}

?>

<?php

if ($next_href) {

echo '<span>'.$next_href.'next'.$next_href2.'</span>';

}else{

echo '<span style="opacity:0.5">next</span>';

}

?>  

<!-- } 다른 상품 보기 끝 -->

</div>

</article>

</section>

</form>

 

<script>

$(function(){

    // 상품이미지 첫번째 링크

    $("#sit_pvi_big a:first").addClass("visible");

 

    // 상품이미지 미리보기 (썸네일에 마우스 오버시)

    $("#sit_pvi .img_thumb").bind("mouseover focus", function(){

        var idx = $("#sit_pvi .img_thumb").index($(this));

        $("#sit_pvi_big a.visible").removeClass("visible");

        $("#sit_pvi_big a:eq("+idx+")").addClass("visible");

    });

    // 상품이미지 크게보기

    $(".popup_item_image").click(function() {

        var url = $(this).attr("href");

        var top = 10;

        var left = 10;

        var opt = 'scrollbars=yes,top='+top+',left='+left;

        popup_window(url, "largeimage", opt);

 

        return false;

    });

// 장바구니 답기

    $("#add_cart_btn").bind("click", function(event){

event.preventDefault();

        var frm = document.getElementById("fitem");

document.pressed = "장바구니";

if(fitem_submit(frm)){

frm.submit();

}

    });

// 수량증가

$("#item_add_btn").bind("click", function(event){

event.preventDefault();

var this_qty, max_qty = 9999, min_qty = 1;

var $el_qty = $("#item_info_area").find("input[name^=ct_qty]");

        var stock = parseInt($("#item_info_area").find("input.io_stock").val());

this_qty = parseInt($el_qty.val().replace(/[^0-9]/, "")) + 1;

        if(this_qty > stock) {

alert("재고수량 보다 많은 수량을 구매할 수 없습니다.");

            this_qty = stock;

        }

        if(this_qty > max_qty) {

this_qty = max_qty;

            alert("최대 구매수량은 "+number_format(String(max_qty))+" 입니다.");

        }

        $el_qty.val(this_qty);

 

    });

 

// 수량감소

$("#item_minus_btn").bind("click", function(event){

event.preventDefault();

var this_qty, max_qty = 9999, min_qty = 1;

var $el_qty = $("#item_info_area").find("input[name^=ct_qty]");

        var stock = parseInt($("#item_info_area").find("input.io_stock").val());

this_qty = parseInt($el_qty.val().replace(/[^0-9]/, "")) - 1;

        if(this_qty < min_qty) {

this_qty = min_qty;

            alert("최소 구매수량은 "+number_format(String(min_qty))+" 입니다.");

        }

        $el_qty.val(this_qty);

 

    });

});

// 바로구매, 장바구니 폼 전송

function fitem_submit(f)

{

var select = document.getElementById("it_option_1");

if(select != null){

var sellength = select.length;

var select_val = select.options[select.selectedIndex].value;

var text = select.options[select.selectedIndex].text;

 

    if (document.pressed == "장바구니") {

        f.sw_direct.value = 0;

if(select_val.length == 0){

alert("옵션을 선택해주세요.");

return false;

}else{

f.text;

alert(text);

}

    } else { // 바로구매

        f.sw_direct.value = 1;

f.text;

}

}else if (document.pressed == "장바구니") {

        f.sw_direct.value = 0;

 

    } else { // 바로구매

        f.sw_direct.value = 1;

 

    }

    // 판매가격이 0 보다 작다면

    if (document.getElementById("it_price").value < 0) {

        alert("전화로 문의해 주시면 감사하겠습니다.");

        return false;

    }

    var val, io_type, result = true;

    var sum_qty = 0;

    var min_qty = parseInt(<?php echo $it['it_buy_min_qty']; ?>);

    var max_qty = parseInt(<?php echo $it['it_buy_max_qty']; ?>);

    var $el_type = $("input[name^=io_type]");

 

    $("input[name^=ct_qty]").each(function(index) {

        val = $(this).val();

        if(val.length < 1) {

            alert("수량을 입력해 주십시오.");

            result = false;

            return false;

        }

        if(val.replace(/[0-9]/g, "").length > 0) {

            alert("수량은 숫자로 입력해 주십시오.");

            result = false;

            return false;

        }

        if(parseInt(val.replace(/[^0-9]/g, "")) < 1) {

            alert("수량은 1이상 입력해 주십시오.");

            result = false;

            return false;

        }

        io_type = $el_type.eq(index).val();

        if(io_type == "0")

            sum_qty += parseInt(val);

    });

    if(!result) {

        return false;

    }

    if(min_qty > 0 && sum_qty < min_qty) {

        alert("선택옵션 개수 총합 "+number_format(String(min_qty))+"개 이상 주문해 주십시오.");

        return false;

    }

    if(max_qty > 0 && sum_qty > max_qty) {

        alert("선택옵션 개수 총합 "+number_format(String(max_qty))+"개 이하로 주문해 주십시오.");

        return false;

    }

    return true;

}

</script>

 

홈페이지 링크가 필요하시다면.. 따로 테스트 아이디와 함께 쪽지로 드리겠습니다..ㅜㅜ

 

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
붉은바람

ㅎㅎ 이렇게 소스를 봐서는 전혀 알수가 없어요. 

URL이랑 계정을 알려줘야 그나마 살펴볼수 있을것 같네요

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

경하귀요밍
8년 전
다른분께서 쪽지주셔서 해결했어요 ㅎㅎ 답변 감사합니다.!!

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인