배송비 관련 질문

배송비 관련 질문

QA

배송비 관련 질문

본문

shop.lib.php입니다.

// 배송비 구함
function get_sendcost($cart_id, $selected=1)
{
    global $default, $g5;



    $send_cost = 0;
    $total_price = 0;
    $total_send_cost = 0;

    $sql = " select distinct it_id, ct_hope_date, ct_delivery 
                from {$g5['g5_shop_cart_table']}
                where od_id = '$cart_id'
                  and ct_send_cost = '0'
                  and ct_status IN ( '쇼핑', '주문', '입금', '준비', '배송', '완료' )
                  and ct_select = '$selected' ";

    $result = sql_query($sql);
    for($i=0; $sc=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_qty) as qty
                    from {$g5['g5_shop_cart_table']}
                    where od_id = '$cart_id'
                      and ct_status IN ( '쇼핑', '주문', '입금', '준비', '배송', '완료' )
                      and ct_select = '$selected'
 and ct_hope_date = '{$sc['ct_hope_date']}'
 and ct_delivery = '{$sc['ct_delivery']}' ";
        $sum = sql_fetch($sql);

        $send_cost = get_item_sendcost($sc['it_id'], $sum['price'], $sum['qty'], $cart_id, $sc['ct_hope_date'], $sc['ct_delivery']);

        if($send_cost > 0)
            $total_send_cost += $send_cost;

        if($default['de_send_cost_case'] == '차등' && $send_cost == -1)
            $total_price += $sum['price'];
    }

    $send_cost = 0;
    if($default['de_send_cost_case'] == '차등' && $total_price > 0) {
        // 금액별차등 : 여러단계의 배송비 적용 가능
        $send_cost_limit = explode(";", $default['de_send_cost_limit']);
        $send_cost_list  = explode(";", $default['de_send_cost_list']);
        $send_cost = 0;
        for ($k=0; $k<count($send_cost_limit); $k++) {
            // 총판매금액이 배송비 상한가 보다 작다면
            if ($total_price < preg_replace('/[^0-9]/', '', $send_cost_limit[$k])) {
                $send_cost = preg_replace('/[^0-9]/', '', $send_cost_list[$k]);
                break;
            }
        }
    }

    return ($total_send_cost + $send_cost);
}


// 상품별 배송비
function get_item_sendcost($it_id, $price, $qty, $cart_id, $ct_hope_date = '0000-00-00', $ct_delivery = '')
{
    global $g5, $default;

    $sql = " select it_id, it_sc_type, it_sc_method, it_sc_price, it_sc_minimum, it_sc_qty, ct_delivery 
                from {$g5['g5_shop_cart_table']}
                where it_id = '$it_id'
                  and od_id = '$cart_id'
 and ct_hope_date = '$ct_hope_date' 
 and ct_delivery = '$ct_delivery' 
                order by ct_id
                limit 1 ";
    $ct = sql_fetch($sql);
    if(!$ct['it_id'])
        return 0;

    if($ct['it_sc_type'] > 1) {
if($ct['it_sc_type'] == 5) { // 조건부무료
$delivery_arr = array('냉장 새벽딜리버리', '냉동 전국택배');
$price_arr = explode(';', $ct['it_sc_price']);
$minimun_arr = explode(';', $ct['it_sc_minimum']);

$key = array_search($ct['ct_delivery'], $delivery_arr);

            if($price >= $minimun_arr[$key]){
                $sendcost = 0;
            }else{
                $sendcost = $price_arr[$key];
}


        } else if($ct['it_sc_type'] == 2) { // 조건부무료
            if($price >= $ct['it_sc_minimum'])
                $sendcost = 0;
            else
                $sendcost = $ct['it_sc_price'];
        } else if($ct['it_sc_type'] == 3) { // 유료배송
            $sendcost = $ct['it_sc_price'];
        } else { // 수량별 부과
            if(!$ct['it_sc_qty'])
                $ct['it_sc_qty'] = 1;

            $q = ceil((int)$qty / (int)$ct['it_sc_qty']);
            $sendcost = (int)$ct['it_sc_price'] * $q;
        }
    } else if($ct['it_sc_type'] == 1) { // 무료배송
        $sendcost = 0;
    } else {
        $sendcost = -1;
    }

    return $sendcost;
}
-------------------------------------------------------------------------------
cart.php
    <tbody>
        <?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,
    a.ct_delivery,
    a.ct_hope_date,
                        b.ca_id,
                        b.ca_id2,
                        b.ca_id3
                   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, a.ct_hope_date, a.ct_delivery ";
        $sql .= " order by a.ct_hope_date, 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 ct_hope_date = '{$row['ct_hope_date']}'
 and ct_delivery = '{$row['ct_delivery']}'
                          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'].'"><b>';
            $a2 = '</b></a>';
            $image = get_it_image($row['it_id'], 70, 70);

            $it_name = $a1 . stripslashes($row['it_name']) . $a2;
$it_name .= '<div>배송방법 : '.$row['ct_delivery'].' / 수령일 : '.$row['ct_hope_date'].'</div>';
            $it_options = print_item_options($row['it_id'], $s_cart_id, $row['ct_hope_date'], $row['ct_delivery']);
            if($it_options) {
                $mod_options = '<div class="sod_option_btn"><button type="button" class="mod_options">선택사항수정</button></div>';
                $it_name .= '<div class="sod_opt">'.$it_options.'</div>';
            }

            // 배송비
            switch($row['ct_send_cost'])
            {
                case 1:
                    $ct_send_cost = '착불';
                    break;
                case 2:
                    $ct_send_cost = '무료';
                    break;
                default:
                    $ct_send_cost = '선불';
                    break;
            }

            // 조건부무료
            if($row['it_sc_type'] == 2) {
                $sendcost = get_item_sendcost($row['it_id'], $sum['price'], $sum['qty'], $s_cart_id);

                if($sendcost == 0)
                    $ct_send_cost = '무료';
            }

// 배송방법별무료
            if($row['it_sc_type'] == 5) {

$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price
from {$g5['g5_shop_cart_table']}
where ct_hope_date = '{$row['ct_hope_date']}'
 and ct_delivery = '{$row['ct_delivery']}'
 and od_id = '$s_cart_id' ";
$tmp_sum = sql_fetch($sql);

                $sendcost = get_item_sendcost($row['it_id'], $tmp_sum['price'], $sum['qty'], $s_cart_id, $row['ct_hope_date'], $row['ct_delivery']);

                if($sendcost == 0)
                    $ct_send_cost = '무료';
            }

            $point      = $sum['point'];
            $sell_price = $sum['price'];
        ?>



<?php if ($send_cost > 0) { // 배송비가 0 보다 크다면 (있다면) ?>
        <dt class="sod_bsk_dvr">배송비</dt>
        <dd class="sod_bsk_dvr"><strong><?php echo number_format($send_cost); ?> 원</strong>
        <?php } ?>

-------------------------------------------------- 중간 필요없는 부분은 생략----


배송비 중에 
배송방법별 부과라고 
추가해서 
 
개발자가 만들어놓고 

배달 날짜, 냉장 or 냉동 배송 방법등을 기준으로 배송비를 결정하는것 같은데

다 잘 된는데 

같은 날 같은 배송방법으로 하되 
기준 금액(30000원)이 안되면
배송비가 추가 됩니다.

그런데 토탈 합해서 배송비가 한번만 추가 되면 되는데 
제품이 3개면 배송비가 3번 추가되서 
제품이 2개면 배송비가 2번 추가되서 
계산이 되는데 어떻게 해야될까요?

이 질문에 댓글 쓰기 :

답변 1

자 여기서 질문하신걸 해결 하려면 간단하게

추가되는 부분에 조건문을 써서 값이 있으면 추가안되게 소스를 짜면됩니다

이소스를 짜는 것이 어렵다고생각되시면 제작의뢰게시판에 알려달라구하세요  

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

회원로그인

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