레벨에 따른 총금액에서 할인율 적용
본문
회원 레벨2 이면 20% 할인
회원 레벨3부터는 30% 할인을 적용하고자 아래 처럼 수정중인데 반응이 없는데
조건문이 어디가 잘못된건지 도움을 구해 봅니다.
shop.js 파일에서
// 가격계산
function price_calculate()
{
var it_price = parseInt($("input#it_price").val());
if(isNaN(it_price))
return;
var $el_prc = $("input.io_price");
var $el_qty = $("input[name^=ct_qty]");
var $el_type = $("input[name^=io_type]");
var price, type, qty, total = 0;
$el_prc.each(function(index) {
price = parseInt($(this).val());
qty = parseInt($el_qty.eq(index).val());
type = $el_type.eq(index).val();
if(type == "0") { // 선택옵션
if($member["mb_level"] == 2) {
total += (it_price + price) * qty * 0.2;
} else if($member["mb_level"] > 2) {
total += (it_price + price) * qty * 0.3;
}
} else { // 추가옵션
total += price * qty;
}
});
$("#sit_tot_price").empty().html("<span>총 상품금액 :</span> <span style='color:red;font-size:18px !important'>"+number_format(String(total))+"원</font>");
}
답변 2
shop.js 파일이면
JavaScript 파일인데
<?php 구문이
.js 에서 작동되게 셋팅되어있나요?
?>
그게 아니시라면
function price_calculate(mblevel) {
변수로 레벨을 넘기고
호출하는곳에서
price_calculate(<?php echo $mb['mb_level']?>);
과 같이 호출해야 합니다.
함수에서
if($member["mb_level"] == 2) {
total += (it_price + price) * qty * 0.2;
} else if($member["mb_level"] > 2) {
total += (it_price + price) * qty * 0.3;
}
이렇게 세팅하신부분에서
넘겨받은 변수로 판단하도록
if(mblevel == 2) {
total += (it_price + price) * qty * 0.2;
} else if(mblevel > 2) {
total += (it_price + price) * qty * 0.3;
}
로 변경하셔야 바르게 작동할겁니다.
.js 가 PHP구문을 허용되게 셋팅되어있다면
하찌님이 답변하신 방법도 잘됩니다.
function price_calculate()
{
var it_price = parseInt($("input#it_price").val());
if(isNaN(it_price))
return;
var $el_prc = $("input.io_price");
var $el_qty = $("input[name^=ct_qty]");
var $el_type = $("input[name^=io_type]");
var price, type, qty, total = 0;
var memberLevel=<?php echo $member['mb_level']?>;
$el_prc.each(function(index) {
price = parseInt($(this).val());
qty = parseInt($el_qty.eq(index).val());
type = $el_type.eq(index).val();
if(type == "0") { // 선택옵션
if( memberLevel== 2) {
total += (it_price + price) * qty * 0.2;
} else if( memberLevel > 2) {
total += (it_price + price) * qty * 0.3;
}
} else { // 추가옵션
total += price * qty;
}
});
$("#sit_tot_price").empty().html("<span>총 상품금액 :</span> <span style='color:red;font-size:18px !important'>"+number_format(String(total))+"원</font>");
}
스크립트 영역에서 $member[''mb_level] 을 불러올 수 없어서
변수로 재가공하여 넣어주셔야 될 것 같습니다
!-->