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

지금 장바구니 전체를 불러오는데 체크된 값만 가져오게 채택완료

블랑숑 5년 전 조회 3,401

</p>

<p>// 예약 상품

$sql = " select ct_reserve, ct_normal, it_id

  from {$g5['g5_shop_cart_table']}

  where od_id = '$tmp_cart_id' ";

$result = sql_query($sql);</p>

<p> </p>

<p>while ($row=sql_fetch_array($result)) {

$sql = " select SUM(ct_reserve) as reserve, SUM(ct_normal) as normal

            from {$g5['g5_shop_cart_table']}

            where od_id = '$tmp_cart_id'

              and it_id = '{$row['it_id']}' ";

$sum = sql_fetch($sql);</p>

<p>

$tot_reserve+= $sum['reserve'];

$tot_normal+= $sum['normal'];</p>

<p>}</p>

<p>

if ( $tot_normal > 0 && $tot_reserve > 0 ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');</p>

<p>

 

이렇게 하니까 각 값이 합산이 되긴 하는데

 

장바구니에서 전체값을 다 불러오네요

 

체크된 값만 불러오게 할 수 있나요?

 

해당 액션 전문입니다

 

</p>

<p>if($act == "buy")

{

    if(!count($_POST['ct_chk']))

        alert("주문하실 상품을 하나이상 선택해 주십시오.");</p>

<p>    // 선택필드 초기화

    $sql = " update {$g5['g5_shop_cart_table']} set ct_select = '0' where od_id = '$tmp_cart_id' ";

    sql_query($sql);</p>

<p>    $fldcnt = count($_POST['it_id']);

    for($i=0; $i<$fldcnt; $i++) {

        $ct_chk = $_POST['ct_chk'][$i];

        if($ct_chk) {

            $it_id = $_POST['it_id'][$i];</p>

<p>            // 본인인증, 성인인증체크

            if(!$is_admin) {

                $msg = shop_member_cert_check($it_id, 'item');

                if($msg)

                    alert($msg, G5_SHOP_URL);

            }</p>

<p>            // 주문 상품의 재고체크

            $sql = " select ct_qty, it_name, ct_option, io_id, io_type, ct_reserve, ct_normal

                        from {$g5['g5_shop_cart_table']}

                        where od_id = '$tmp_cart_id'

                          and it_id = '$it_id' ";

            $result = sql_query($sql);</p>

<p>            for($k=0; $row=sql_fetch_array($result); $k++) {

                $sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']}

                          where od_id <> '$tmp_cart_id'

                            and it_id = '$it_id'

                            and io_id = '{$row['io_id']}'

                            and io_type = '{$row['io_type']}'

                            and ct_stock_use = 0

                            and ct_status = '쇼핑'

                            and ct_select = '1' ";

                $sum = sql_fetch($sql);

                $sum_qty = $sum['cnt'];</p>

<p>                // 재고 구함

                $ct_qty = $row['ct_qty'];

                if(!$row['io_id'])

                    $it_stock_qty = get_it_stock_qty($it_id);

                else

                    $it_stock_qty = get_option_stock_qty($it_id, $row['io_id'], $row['io_type']);</p>

<p>                if ($ct_qty + $sum_qty > $it_stock_qty)

                {

                    $item_option = $row['it_name'];

                    if($row['io_id'])

                        $item_option .= '('.$row['ct_option'].')';</p>

<p>                    alert($item_option." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개");

                }

            }</p>

<p>            //장바구니 품절

            $sql = " select b.it_soldout

                                  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 = '$tmp_cart_id'

                                  and a.it_id = '$it_id' ";

            $res = sql_query($sql);</p>

<p>            while ($row=sql_fetch_array($res)){</p>

<p>                if ($row['it_soldout'])

                {

                    alert("주문하시려는 상품 중 품절인 상품이 있습니다.");

                }

            }</p>

<p>            // 예약 상품

            $sql = " select ct_reserve, ct_normal, it_id

              from {$g5['g5_shop_cart_table']}

              where od_id = '$tmp_cart_id' ";

            $result = sql_query($sql);</p>

<p> </p>

<p>            while ($row=sql_fetch_array($result)) {

            $sql = " select SUM(ct_reserve) as reserve, SUM(ct_normal) as normal

                        from {$g5['g5_shop_cart_table']}

                        where od_id = '$tmp_cart_id'

                          and it_id = '{$row['it_id']}' ";

            $sum = sql_fetch($sql);</p>

<p>

            $tot_reserve+= $sum['reserve'];

            $tot_normal+= $sum['normal'];</p>

<p>            }</p>

<p> </p>

<p>            if ( $tot_normal > 0 && $tot_reserve > 0 ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');</p>

<p> </p>

<p>            $sql = " update {$g5['g5_shop_cart_table']}

                        set ct_select = '1',

                            ct_select_time = '".G5_TIME_YMDHIS."'

                        where od_id = '$tmp_cart_id'

                          and it_id = '$it_id' ";

            sql_query($sql);

        }

    }</p>

<p>    if ($is_member) // 회원인 경우

        goto_url(G5_SHOP_URL.'/orderform.php');

    else

        goto_url(G5_BBS_URL.'/login.php?url='.urlencode(G5_SHOP_URL.'/orderform.php'));

}</p>

<p>

 

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

답변 2개

채택된 답변
+20 포인트
Policia
5년 전

체크된값만 가져오는거면 예약상품 쿼리에 and it_id = '$it_id' 다시 넣어야할것같네요

몇번보다니보니 체크된상품에 예약상품 여부를 확인할려고하시는것같은데 굳이 쿼리를 나누기보다는 재고체크할때 같이 들어가도 될것같네요

예약상품이면 ct_reserve = 1 인거죠? 재고검사할때 예약상품인지 체크하고 예약상품이면 $tot_reserve++;로 처리를해줄수있을것같네요

 

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

답변에 대한 댓글 5개

블랑숑
5년 전
오 그걸 넣으니 정상작동 하네요 감사합니다 ㅠㅠ

근데 재고검사할때 그건 어떻게 넣나요?
블랑숑
5년 전
예약상품이면 알러트는 아니고

일반 상품이랑 예약상품이랑 같이 주문하면 알러트입니다

그래서 일반상품에는 ct_normal = 1 이 들어가게 해놨어요
블랑숑
5년 전
사실 원래 예약상품은 it_2 = 1 이고 아닌 상품은 it_2 =''

인데 제가 부족하다보니 많은 도움을 받는 과정에서

it_2로 처리하는거보다 값을 따로 넣어서 하는게 더 편하겠다 생각해서

이렇게 변형된거에요 ㅎㅎ 진짜 3일 동안 꼬박 이것만 붙잡았네요 ㅠㅠ
P
Policia
5년 전
쿼리문은 최대한 줄이는게 퍼포먼스에 좋으니
어차피 체크된 상품을 재고검사할때 한번씩 확인하잖아요 여기서
//주문 상품의 재고체크 밑에 쿼리에서 ct_reserve, ct_normal값을 가져올수있도록 추가하고
그다음 for문에서
if($row['ct_reserve']) $tot_reserve++;
else if($row['ct_noraml']) $tot_normal++;
이런식으로 해당 상품일경우 체크합니다
물론 for문 들어가기 이전에 $tot_reserve = $tot_normal = 0; 선언해주시구요

그런다음 for문 빠져나왔을때(재고체크가 끝났을떄)
if ( $tot_normal > 0 && $tot_reserve > 0 ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');
얼럿을 추가해주시면 간단하게 쿼리문 두개나 추가안하여도 체크가 가능하죠
블랑숑
5년 전
밑 새답변에 적용시킨 소스 올려놨는데

작동안되네요 ㅠㅠ

그나저나 너무 친절하시고 감사해요 공부 도움이 많이 됩니다 진짜루요

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

5년 전

</p>

<p>            // 주문 상품의 재고체크

            $sql = " select ct_qty, it_name, ct_option, io_id, io_type, ct_normal, ct_reserve

                        from {$g5['g5_shop_cart_table']}

                        where od_id = '$tmp_cart_id'

                          and it_id = '$it_id' ";

            $result = sql_query($sql);</p>

<p>            $tot_reserve = $tot_normal = 0; </p>

<p>            for($k=0; $row=sql_fetch_array($result); $k++) {

                $sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']}

                          where od_id <> '$tmp_cart_id'

                            and it_id = '$it_id'

                            and io_id = '{$row['io_id']}'

                            and io_type = '{$row['io_type']}'

                            and ct_stock_use = 0

                            and ct_status = '쇼핑'

                            and ct_select = '1' ";

                $sum = sql_fetch($sql);

                $sum_qty = $sum['cnt'];

                if($row['ct_reserve']) $tot_reserve++;

                else if($row['ct_normal']) $tot_normal++;</p>

<p>                // 재고 구함

                $ct_qty = $row['ct_qty'];

                if(!$row['io_id'])

                    $it_stock_qty = get_it_stock_qty($it_id);

                else

                    $it_stock_qty = get_option_stock_qty($it_id, $row['io_id'], $row['io_type']);</p>

<p>                if ($ct_qty + $sum_qty > $it_stock_qty)

                {

                    $item_option = $row['it_name'];

                    if($row['io_id'])

                        $item_option .= '('.$row['ct_option'].')';</p>

<p>                    alert($item_option." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개");

                }

            }</p>

<p>            if ( $tot_normal > 0 && $tot_reserve > 0 ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');</p>

<p>

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

답변에 대한 댓글 2개

P
Policia
5년 전
이상하네요 딱맞는데 ㅎㅎ 음 기존에 sum하신거보면 ct_resrve , ct_normal이 처리가 어떻게 되어있는걸까요?
해당 코드만으로 판단하기엔 sum부분 쿼리문은 굳이 필요없다 판단했는데 아닌가보네요
블랑숑
5년 전
아닌 것은 0, 긴 것은 1 이케 돼 있었어요

뭔가 제가 놓친게 있나봐요 ㅠㅠ 저는 완전 초짜라 ㅎㅎ

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

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

로그인