[Y5] 장바구니 담긴후 가격이 변경된 경우 > 기술자료

본문 바로가기

사이트 내 전체검색

[Y5] 장바구니 담긴후 가격이 변경된 경우 > 기술자료

영카트 [Y5] 장바구니 담긴후 가격이 변경된 경우

페이지 정보


본문

장바구니에 담긴후 상품 가격이 변경되었습니다.
이후 고객이 장바구니에 있는 상품을 구매를 진행할때 가격이 변경되도록 하는 방법입니다.
영카트 5.xx 이전 버전에는 아래와 같이 추가합니다.


1. lib / shop.data.lib.php  파일이 존재하는 확인
get_shop_item  함수가 있는지 확인

없으면  lib / shop.lib.php  끝에  아래 함수 추가

// lib/shop.data.lib.php 에 포함된 내용
if(!function_exists("get_shop_item")) {
function get_shop_item($it_id, $is_cache=false, $add_query=''){
    
    global $g5, $g5_object;

    $add_query_key = $add_query ? 'shop_'.md5($add_query) : '';

    $item = $is_cache ? $g5_object->get('shop', $it_id, $add_query_key) : null;

    if( !$item ){
        $sql = " select * from {$g5['g5_shop_item_table']} where it_id = '{$it_id}' $add_query ";
        $item = sql_fetch($sql);

        $g5_object->set('shop', $it_id, $item, $add_query_key);
    }
    
    if( isset($item['it_basic']) ) {
        $item['it_basic'] = conv_content($item['it_basic'], 1);
    }

    if( ! isset($item['it_id']) ){
        $item['it_id'] = '';
    }

    return $item;
}
}


2. lib / shop.lib.php 내용에서  before_check_cart_price  검색후 내용이 없으면 끝에 아래 내용 추가합니다.
if(!function_exists("before_check_cart_price")) {
// 장바구니 금액 체크 $is_price_update 가 true 이면 장바구니 가격 업데이트한다. 
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);
        
        $update_querys = array();
        if(!$it['it_id'])
            continue;
        
        if( $it['it_price'] !== $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;
}
}


3. shop/cart.php 에  before_check_cart_price 가 있는지 확인하고, 없으면  include_once('./_common.php');  밑에 아래 내용을 추가합니다.
if(function_exists('before_check_cart_price')) {
    before_check_cart_price($s_cart_id, true, true, true);
}



참고자료
https://sir.kr/qa/503815
label

댓글목록

등록된 댓글이 없습니다.


Total 2,650건 3 페이지
  • RSS
기술자료 목록
2610
전자결제   3786  2023-08-24 13:32  
2609
Editor   3871  2023-08-11 12:23  
2608
Editor   4125  2023-08-09 21:54 ~ 2023-08-09 21:56  
2607
JavaScript   3773  2023-08-01 23:01 ~ 2023-08-01 23:35  
2606
Android   3432  2023-07-19 14:30 ~ 2023-07-19 14:39  
2605
MSSQL   4274  2023-06-28 17:51 ~ 2023-06-28 17:53  
2604
Android   3649  2023-06-09 17:06 ~ 2023-06-13 16:49  
2603
MySQL   6748  2023-04-25 11:36 ~ 2023-04-25 11:37  
2602
PHP   5507  2023-04-14 18:22 ~ 2023-04-14 18:40  
2601
그누보드   4683  2023-04-07 18:22 ~ 2023-04-07 18:40  
2600
일반   4028  2023-04-07 13:30  
2599
HTML   5698  2023-04-07 09:52 ~ 2023-04-07 09:59  
2598
그누보드   4825  2023-04-07 08:45 ~ 2023-04-07 10:00  
2597
그누보드   5651  2023-04-06 22:37  
2596
Editor   6121  2023-03-31 09:54 ~ 2023-03-31 12:51  
2595
Android   14406  2023-03-29 16:25 ~ 2023-11-21 13:33  
2594
Linux   4409  2023-03-28 18:09 ~ 2023-03-28 18:11  
2593
Android   4888  2023-03-07 12:06 ~ 2023-03-20 11:02  
2592
Android   4287  2023-03-07 11:28 ~ 2023-03-07 11:35  
2591
호스팅   4680  2023-03-06 15:52 ~ 2023-12-18 16:54  

검색

해피정닷컴 정보

회사소개 회사연혁 협력사 오시는길 서비스 이용약관 개인정보 처리방침

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 1동 222호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 제2024-대전대덕-0405호 [사업자등록확인]  
Copyright 2001~2026 해피정닷컴. All Rights Reserved.