배송비 관련 질문입니다.
본문
naulab 님 답변 감사합니다.
글자 제한이 있어 이곳에 다시 적습니다.
- 이전질문 - 영카드5를 사용하다 일반 상품 외의 특수상품이 구입이 필요하여 별도 상품테이블을 만들고 특정 버튼을 클릭하면 영카트 장바구니에 들어가게 하였습니다. 영카트 상품일때만 배송료가 부가되고 특수상품일때는 배송료가 부가 않되게 하고자 합니다. |
print_r($row) 로 출력해보니 원하는 stat 값이 잘 나옵니다.
아무래도 for ($i=0; $row=sql_fetch_array($result); $i++) 밖에 원하는 부분이 있어 작동을 하지 않은 것 같습니다.
for ($i=0; $row=sql_fetch_array($result); $i++) { 밖에서 $row를 불러 올려 합니다.
이럴경우 어떻게 해 주어야 하나요?
<!-- 장바구니 시작 { -->
<script src="<?php echo G5_JS_URL; ?>/shop.js"></script>
<div id="sod_bsk">
<form name="frmcartlist" id="sod_bsk_list" method="post" action="<?php echo $cart_action_url; ?>">
<div class="tbl_head01 tbl_wrap">
<table>
<thead>
<tr>
<th scope="col">이미지</th>
<th scope="col">처방명</th>
<th scope="col">처방건수</th>
<th scope="col">처방가격</th>
<th scope="col">소계</th>
<!--<th scope="col">포인트</th>
<th scope="col">배송비</th>-->
<th scope="col">
<label for="ct_all" class="sound_only">상품 전체</label>
<input type="checkbox" name="ct_all" value="1" id="ct_all" checked="checked">
</th>
</tr>
</thead>
<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.stat,
a.ct_status,
a.ct_send_cost,
a.it_sc_type,
b.chname,
b.byg
from {$g5['g5_shop_cart_table']} a left join ib_order b on ( b.stat=a.ct_stat or b.stat=a.it_id )
where a.od_id = '$s_cart_id'";
$sql .= " group by it_id ";
$sql .= " order by ct_id ";
$result = sql_query($sql);
$it_send_cost = 0;
for ($i=0; $row=sql_fetch_array($result); $i++)
{
//print_r($row);
// 합계금액 계산
$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 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);
if($row[chname]){
$image = "<img src='../wontang/attfile/$row[byg].jpg' height='70px' width='70px'>";
} else {
$image = get_it_image($row['it_id'], 70, 70);
}
$stat = "";
if($row[ct_stat]) $stat = $row[ct_stat];
else $stat = $row[it_id];
$it_name = $a1 . stripslashes($row['it_name']) . $a2;
$it_options = print_item_options($row['it_id'], $s_cart_id);
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 = '무료';
}
$point = $sum['point'];
$sell_price = $sum['price'];
?>
<tr>
<td class="sod_img"><?php echo $image; ?></td>
<td>
<input type="hidden" name="it_id[<?php echo $i; ?>]" value="<?php echo $row['it_id']; ?>">
<input type="hidden" name="it_name[<?php echo $i; ?>]" value="<?php echo get_text($row['it_name']); ?>">
<?//php echo $it_name; ?>
<? if($row[chname]){
echo $row[chname]." <a href='javascript:' onclick=\"javascript:window.open('won.cart.php?stat=$stat','cartinfo','width=680,height=838,scrollbars=yes');\"><img src='../shop/img/btn_jumuninfo.gif' border=0 align=absmiddle></a>";
}
else{
echo $it_name.$mod_options;
} ?>
</td>
<td class="td_numbig"><?php echo number_format($sum['qty']); ?></td>
<td class="td_numbig"><?php echo number_format($row['ct_price']); ?></td>
<td class="td_numbig"><span id="sell_price_<?php echo $i; ?>"><?php echo number_format($sell_price); ?></span></td>
<!--<td class="td_numbig"><?php echo number_format($point); ?></td>
<td class="td_dvr"><?php echo $ct_send_cost; ?></td>-->
<td class="td_chk">
<label for="ct_chk_<?php echo $i; ?>" class="sound_only">상품</label>
<input type="checkbox" name="ct_chk[<?php echo $i; ?>]" value="1" id="ct_chk_<?php echo $i; ?>" checked="checked">
</td>
</tr>
<?php
$tot_point += $point;
$tot_sell_price += $sell_price;
} // for 끝
if ($i == 0) {
echo '<tr><td colspan="8" class="empty_table">장바구니에 담긴 처방이 없습니다.</td></tr>';
} else {
// 배송비 계산
$send_cost = get_sendcost($s_cart_id, 0);
}
?>
</tbody>
</table>
</div>
<?php
$tot_price = $tot_sell_price + $send_cost; // 총계 = 주문상품금액합계 + 배송비
$to_price = $tot_sell_price + $send_cost; // 총계 = 주문상품금액합계
$stat2 = $row['stat'];
if ($tot_price > 0 || $send_cost > 0) {
?>
<dl id="sod_bsk_tot">
<?php if($row['stat']==0) { ?>
<?php if ($send_cost > 0) { // 배송비가 0 보다 크다면 (있다면) ?>
<dt class="sod_bsk_dvr">배송비<? echo $stat2; ?></dt>
<dd class="sod_bsk_dvr"><strong><?php echo number_format($send_cost); ?> 원</strong></dd>
<?php } ?>
<?php } else { ?>
<?php } ?>
<?php
if ($tot_price > 0) {
?>
<dt class="sod_bsk_cnt">총계 가격</dt>
<dd class="sod_bsk_cnt"><strong><?php echo number_format($tot_price); ?> 원 </strong></dd>
<?php } ?>
</dl>
<?php } ?>
!-->
답변 2
for 문 밖에서 변경할 변수를 선언하시고
for 문 안에서 $row['stat'] 의 값에따라 그 변수를 변경하시면될거같습니다
예를들어 for 문밖에 statYN = 'N';
for문안에서
if($row['stat'] == 'won')
{
$statYN = 'Y';
}
그 이후 밖에서 저 변수를 if문에 사용하시면 될거같네요
특수상품 구분을 어떻게 하는지 모르겠지만 특수상품 여부를 체크해서 배송비를 더해주고 처리 안되도록 하시면 될듯 보여지는데요
답변을 작성하시기 전에 로그인 해주세요.