From c6669f76e56d2de1e7e9ddd040362d515f95021b Mon Sep 17 00:00:00 2001 From: thisgun Date: Wed, 28 Oct 2020 15:13:16 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=A5=EB=B0=94=EA=B5=AC=EB=8B=88=20?= =?UTF-8?q?=EA=B0=80=EA=B2=A9=20=EB=B3=80=EB=8F=99=20=EC=82=AC=ED=95=AD=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/shop.lib.php | 95 ++++++++++++++++++++++++++++++++++++++++ shop/ajax.orderstock.php | 4 ++ shop/cart.php | 4 ++ shop/orderform.php | 4 ++ 4 files changed, 107 insertions(+) diff --git a/lib/shop.lib.php b/lib/shop.lib.php index 32cb08716..24c0fe3e7 100644 --- a/lib/shop.lib.php +++ b/lib/shop.lib.php @@ -2469,6 +2469,101 @@ function shop_is_taxsave($od, $is_view_receipt=false){ return 0; } +// 장바구니 금액 체크 $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; +} + // 장바구니 상품삭제 function cart_item_clean() { diff --git a/shop/ajax.orderstock.php b/shop/ajax.orderstock.php index bf5c66d7b..6e4eae453 100644 --- a/shop/ajax.orderstock.php +++ b/shop/ajax.orderstock.php @@ -37,6 +37,10 @@ if($cart_stock_limit > 0) { die("주문 요청 때까지 ".$cart_stock_limit."시간 이상 경과되어 주문 상품이 초기화 됐습니다.\n\n 장바구니에서 주문하실 상품을 다시 확인해 주십시오."); } +if (function_exists('before_check_cart_price')) { + if(! before_check_cart_price($tmp_cart_id) ) die("장바구니 금액에 변동사항이 있습니다.\n장바구니를 다시 확인해 주세요."); +} + // 재고체크 $sql = " select * from {$g5['g5_shop_cart_table']} diff --git a/shop/cart.php b/shop/cart.php index 4eac1cbe1..739ad4860 100644 --- a/shop/cart.php +++ b/shop/cart.php @@ -15,6 +15,10 @@ sql_query($sql); $cart_action_url = G5_SHOP_URL.'/cartupdate.php'; +if(function_exists('before_check_cart_price')) { + before_check_cart_price($s_cart_id, true, true, true); +} + if (G5_IS_MOBILE) { include_once(G5_MSHOP_PATH.'/cart.php'); return; diff --git a/shop/orderform.php b/shop/orderform.php index 731ec4352..d056c5782 100644 --- a/shop/orderform.php +++ b/shop/orderform.php @@ -24,6 +24,10 @@ else { if (get_cart_count($tmp_cart_id) == 0) alert('장바구니가 비어 있습니다.', G5_SHOP_URL.'/cart.php'); +if (function_exists('before_check_cart_price')) { + if(! before_check_cart_price($tmp_cart_id) ) alert('장바구니 금액에 변동사항이 있습니다.\n장바구니를 다시 확인해 주세요.', G5_SHOP_URL.'/cart.php'); +} + // 새로운 주문번호 생성 $od_id = get_uniqid(); set_session('ss_order_id', $od_id);