IT 정보

영카트 상품별 금액 변동 코드

jerry99 2024. 9. 26. 13:29

상품 금액 8이상시 금액 변동 해당 사항 코드들 수정 내역

1. adm/shop_admin/itemform.php

//38 라인에 해당 사항 추가 등급 금액 변수 초기화
'it_price_b'=>0,

//618 라인 해당 회원 가격 추가
 <tr>
            <th scope="row"><label for="it_price">판매가격</label></th>
            <td>
                <input type="text" name="it_price" value="<?php echo $it['it_price']; ?>" id="it_price" class="frm_input" size="8"> 원
            </td>
            <th scope="row"><label for="it_price_b">회원가격</label></th>
            <td>
                <input type="text" name="it_price_b" value="<?php echo $it['it_price_b']; ?>" id="it_price_b" class="frm_input" size="8"> 원
            </td>
            <td class="td_grpset">
                <input type="checkbox" name="chk_ca_it_price" value="1" id="chk_ca_it_price">
                <label for="chk_ca_it_price">분류적용</label>
                <input type="checkbox" name="chk_all_it_price" value="1" id="chk_all_it_price">
                <label for="chk_all_it_price">전체적용</label>
            </td>
        </tr>
        

2. adm/shop_admin/itemform.php

//308 라인 추가
'it_price',             // 판매가격
'it_price_b',           // 등급가격

//364라인 해당 쿼리 추가
							  it_price            = '$it_price',
                it_price_b          = '$it_price_b',
                
                

3. lib/shop.lib

// 금액표시
// $it : 상품 배열
function get_price($it)
{
    global $member;

    if ($it['it_tel_inq']) return '전화문의';

    $price = $it['it_price'];

      if ($member['mb_level'] > 8){
        if ($it['it_price_b'] !== '' && $it['it_price_b'] !== '0' && $it['it_price_b'] !== null){
            $price = $it['it_price_b'];
        }
    }

    return (int)$price;
}

//get price 함수 해당 내용 추가 레벨이 높을 경우 it_price_b 로 출력

여기 까지 진행하였을때 update 부분에서 카트나 장바구니로 이동시 금액이 누락이 됨

4. shop/cart_update.php

 // 배송비결제 //358라인
            if($it['it_sc_type'] == 1)
                $ct_send_cost = 2; // 무료
            else if($it['it_sc_type'] > 1 && $it['it_sc_method'] == 1)
                $ct_send_cost = 1; // 착불
            
            $io_value = sql_real_escape_string(strip_tags($io_value));
            $remote_addr = get_real_client_ip();

            //해당 레벨 추가로 금액 변동
            if ($member['mb_level'] > 8){
                $it['it_price'] = $it['it_price_b'];
            }

            $sql .= $comma."( '$tmp_cart_id', '{$member['mb_id']}', '{$it['it_id']}', '".addslashes($it['it_name'])."', '{$it['it_sc_type']}', '{$it['it_sc_method']}', '{$it['it_sc_price']}', '{$it['it_sc_minimum']}', '{$it['it_sc_qty']}', '쇼핑', '{$it['it_price']}', '$point', '0', '0', '$io_value', '$ct_qty', '{$it['it_notax']}', '$io_id', '$io_type', '$io_price', '".G5_TIME_YMDHIS."', '$remote_addr', '$ct_send_cost', '$sw_direct', '$ct_select', '$ct_select_time' )";
            $comma = ' , ';
            $ct_count++;
            
            

여기 까지 진행시 장바구니 금액에 변동이 있다는 오류가 발생 해결 방안

5 . lib/shop.lib.php

// 장바구니 금액 체크 $is_price_update 가 true 이면 장바구니 가격 업데이트한다. 
//해당 장바구니 함수를 재정의 하여 사용 해당 코드 복사해서 사용할시 오류 x

function before_check_cart_price($s_cart_id, $is_ct_select_condition=false, $is_price_update=false, $is_item_cache=false){

    global $g5, $default, $config;

    if( !$s_cart_id ){

        return;

    }

    $select_where_add = '';

    if( $is_ct_select_condition ){

        $select_where_add = " and ct_select = '0' ";

    }

    $sql = " select * from `{$g5['g5_shop_cart_table']}` where od_id = '$s_cart_id' {$select_where_add} ";

    $result = sql_query($sql);

    $check_need_update = false;

    

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

        if( ! $row['it_id'] ) continue;

        $it_id = $row['it_id'];

        $it = get_shop_item($it_id, $is_item_cache);

		$it['it_price'] = get_price($it);

        $update_querys = array();

        if(!$it['it_id'])

            continue;

        

        if( (int)$it['it_price'] !== (int)$row['ct_price'] ){

            // 장바구니 테이블 상품 가격과 상품 테이블의 상품 가격이 다를경우

            $update_querys['ct_price'] = $it['it_price'];

        }

        if( $row['io_id'] ){

            $io_sql = " select * from {$g5['g5_shop_item_option_table']} where it_id = '{$it['it_id']}' and io_id = '{$row['io_id']}' ";

            $io_infos = sql_fetch( $io_sql );

            if( $io_infos['io_type'] ){

                $this_io_type = $io_infos['io_type'];

            }

            if( $io_infos['io_id'] && $io_infos['io_price'] !== $row['io_price'] ){

                // 장바구니 테이블 옵션 가격과 상품 옵션테이블의 옵션 가격이 다를경우

                $update_querys['io_price'] = $io_infos['io_price'];

            }

        }

        // 포인트

        $compare_point = 0;

        if($config['cf_use_point']) {

            // DB 에 io_type 이 1이면 상품추가옵션이며, 0이면 상품선택옵션이다

            if($row['io_type'] == 0) {

                $compare_point = get_item_point($it, $row['io_id']);

            } else {

                $compare_point = $it['it_supply_point'];

            }

            if($compare_point < 0)

                $compare_point = 0;

        }

        

        if((int) $row['ct_point'] !== (int) $compare_point){

            // 장바구니 테이블 적립 포인트와 상품 테이블의 적립 포인트가 다를경우

            $update_querys['ct_point'] = $compare_point;

        }

        if( $update_querys ){

            $check_need_update = true;

        }

        // 장바구니에 담긴 금액과 실제 상품 금액에 차이가 있고, $is_price_update 가 true 인 경우 장바구니 금액을 업데이트 합니다. 

        if( $is_price_update && $update_querys ){

            $conditions = array();

            foreach ($update_querys as $column => $value) {

                $conditions[] = "`{$column}` = '{$value}'";

            }

            if( $col_querys = implode(',', $conditions) ) {

                $sql_query = "update `{$g5['g5_shop_cart_table']}` set {$col_querys} where it_id = '{$it['it_id']}' and od_id = '$s_cart_id' and ct_id =  '{$row['ct_id']}' ";

                sql_query($sql_query, false);

            }

        }

    }

    // 장바구니에 담긴 금액과 실제 상품 금액에 차이가 있다면

    if( $check_need_update ){

        return false;

    }

    return true;

}

ㄴㅇㄹ

해당 코드를 수정해서 작업 진행시 정상적으로 금액 변동하여 사용 가능