배송비 관련 질문입니다. 채택완료
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를 불러 올려 합니다.
이럴경우 어떻게 해 주어야 하나요?
</p><p><!-- 장바구니 시작 { -->
<script src="<?php echo G5_JS_URL; ?>/shop.js"></script></p><p><div id="sod_bsk"></p><p> <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;</p><p> // $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);</p><p> $it_send_cost = 0;</p><p> 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);</p><p> if ($i==0) { // 계속쇼핑
$continue_ca_id = $row['ca_id'];
}</p><p> $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];</p><p> $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>';
}</p><p> // 배송비
switch($row['ct_send_cost'])
{
case 1:
$ct_send_cost = '착불';
break;
case 2:
$ct_send_cost = '무료';
break;
default:
$ct_send_cost = '선불';
break;
}</p><p> // 조건부무료
if($row['it_sc_type'] == 2) {
$sendcost = get_item_sendcost($row['it_id'], $sum['price'], $sum['qty'], $s_cart_id);</p><p> if($sendcost == 0)
$ct_send_cost = '무료';
}</p><p> $point = $sum['point'];
$sell_price = $sum['price'];
?></p><p> <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;</p><p> } ?>
</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></p><p> <?php
$tot_point += $point;
$tot_sell_price += $sell_price;
} // for 끝</p><p> 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></p><p> <span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"><?php</span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> $tot_price = $tot_sell_price + $send_cost; // 총계 = 주문상품금액합계 + 배송비</span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> $to_price = $tot_sell_price + $send_cost; // 총계 = 주문상품금액합계</span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> $stat2 = $row['stat'];</span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> if ($tot_price > 0 || $send_cost > 0) {</span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> ?></span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> <dl id="sod_bsk_tot"></span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> <?php if($row['stat']==0) { ?> </span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> <?php if ($send_cost > 0) { // 배송비가 0 보다 크다면 (있다면) ?></span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> <dt class="sod_bsk_dvr">배송비<? echo $stat2; ?></dt></span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> <dd class="sod_bsk_dvr"><strong><?php echo number_format($send_cost); ?> 원</strong></dd></span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> <?php } ?></span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> <?php } else { ?></span>
<span style="color: rgb(255, 255, 255); background-color: rgb(255, 167, 0);"> <?php } ?></span>
<?php
if ($tot_price > 0) {
?></p><p> <dt class="sod_bsk_cnt">총계 가격</dt>
<dd class="sod_bsk_cnt"><strong><?php echo number_format($tot_price); ?> 원 </strong></dd>
<?php } ?></p><p> </dl>
<?php } ?></p><p>
답변 2개
for 문 밖에서 변경할 변수를 선언하시고
for 문 안에서 $row['stat'] 의 값에따라 그 변수를 변경하시면될거같습니다
예를들어 for 문밖에 statYN = 'N';
for문안에서
if($row['stat'] == 'won')
{
$statYN = 'Y'; }
그 이후 밖에서 저 변수를 if문에 사용하시면 될거같네요
답변에 대한 댓글 2개
if($row['stat'] == 'won')
{
$statYN = 'Y';
}
이런식으로 넣어주시고 밑에서 말씀해주신 if 문을 사용해보세요
댓글을 작성하려면 로그인이 필요합니다.
특수상품 구분을 어떻게 하는지 모르겠지만 특수상품 여부를 체크해서 배송비를 더해주고 처리 안되도록 하시면 될듯 보여지는데요
답변에 대한 댓글 3개
그걸 이용해서
<?php if($row['stat']==0) { ?> if문을 할려는데 않먹혀 드린 질문입니다.
{
//print_r($row);
if($row['stat'] == 'won')
{
$statYN = 'Y';
}
}
중략
<?php
$statYN = 'N';
$tot_price = $tot_sell_price + $send_cost; // 총계 = 주문상품금액합계 + 배송비
$to_price = $tot_sell_price + $send_cost; // 총계 = 주문상품금액합계
if ($tot_price > 0 || $send_cost > 0) {
?>
<dl id="sod_bsk_tot">
<?php
if($statYN == 'N') { ?>
<?php if ($send_cost > 0) { // 배송비가 0 보다 크다면 (있다면) ?>
<dt class="sod_bsk_dvr">배송비<? echo $statYN; ?></dt>
<dd class="sod_bsk_dvr"><strong><?php echo number_format($send_cost); ?> 원</strong></dd>
<?php } ?>
<?php } else { ?>
<?php } ?>
답변 정말 감사합니다.
위 처럼하고 확인 해 보았는데 그대로네요^^;
if($row['stat'] == 'won')
{
$statYN = 'Y';
} else {
$statYN = 'N';
}
위와 같이 하니 되네요^^;
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
말씀대로 하고 for문 밖에 statYN = 'N';을 했을때 if문을 어떻게 해야 하나요?^^;
for문 밖에 statYN = 'N'; 있기 때문에
if ($statYN == 'N') {
보일내용
} else {
}
위처럼 하면 않되는데 뭘 잘못 한건가요?