레벨에 따른 총금액에서 할인율 적용

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
레벨에 따른 총금액에서 할인율 적용

QA

레벨에 따른 총금액에서 할인율 적용

본문

회원 레벨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] 을 불러올 수 없어서 

변수로 재가공하여 넣어주셔야 될 것 같습니다

답변을 작성하시기 전에 로그인 해주세요.
전체 10
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT