메인 상품 리스트에 장바구니 버튼만들었을때 질문입니다.

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
메인 상품 리스트에 장바구니 버튼만들었을때 질문입니다.

QA

메인 상품 리스트에 장바구니 버튼만들었을때 질문입니다.

본문

테마의 redshop의 메인 신상품 리스트에 장바구니와 위시리스트 버튼을 넣었습니다.

그런데 위시리스트 버튼은 잘 작동하는데요 장바구니 버튼은 아무런 반응이 없어서 그럽니다.

어디를 보아야 하나요?

 

theme/redshop/skin/shop/basic/main.10.skin.php

 

echo"<div class=\"sct_btn\">
            <div class=\"sct_cart_btn\">
                <button type=\"button\" class=\"btn_cart\" data-it_id=\"{$row['it_id']}\"><span class=\"btn_txt\">장바구니</span><br><i class=\"fa fa-shopping-cart\" aria-hidden=\"true\"></i></button>
                <button type=\"button\" class=\"btn_wish\" data-it_id=\"{$row['it_id']}\"><span class=\"btn_txt\">위시리스트</span><br><i class=\"fa fa-heart\" aria-hidden=\"true\"></i></button>
            </div>
        </div>\n";
 

 

 

theme/redshop/js/jquery.shop.list.js

 


$(function () {
    $(document).on("click", ".btn_cart", function() {
        var it_id = $(this).data("it_id");
        var $opt = $(this).closest("li.sct_li").find(".sct_cartop");
        var $btn = $(this).closest("li.sct_li").find(".sct_btn");
        $(".sct_cartop").not($opt).css("display", "");
        $.ajax({
            url: g5_theme_shop_url+"/ajax.itemoption.php",
            type: "POST",
            data: {
                "it_id" : it_id
            },
            dataType: "json",
            async: true,
            cache: false,
            success: function(data, textStatus) {
                if(data.error != "") {
                    alert(data.error);
                    return false;
                }
                $opt.html(data.html);
                if(!data.option) {
                    add_cart($opt.find("form").get(0));
                    return;
                }
                $btn.css("display","none");
                $opt.css("display","block");
            }
        });
    });
    $(document).on("change", "select.it_option", function() {
        var $frm = $(this).closest("form");
        var $sel = $frm.find("select.it_option");
        var sel_count = $sel.size();
        var idx = $sel.index($(this));
        var val = $(this).val();
        var it_id = $frm.find("input[name='it_id[]']").val();
        // 선택값이 없을 경우 하위 옵션은 disabled
        if(val == "") {
            $frm.find("select.it_option:gt("+idx+")").val("").attr("disabled", true);
            return;
        }
        // 하위선택옵션로드
        if(sel_count > 1 && (idx + 1) < sel_count) {
            var opt_id = "";
            // 상위 옵션의 값을 읽어 옵션id 만듬
            if(idx > 0) {
                $frm.find("select.it_option:lt("+idx+")").each(function() {
                    if(!opt_id)
                        opt_id = $(this).val();
                    else
                        opt_id += chr(30)+$(this).val();
                });
                opt_id += chr(30)+val;
            } else if(idx == 0) {
                opt_id = val;
            }
            $.post(
                g5_shop_url + "/itemoption.php",
                { it_id: it_id, opt_id: opt_id, idx: idx, sel_count: sel_count },
                function(data) {
                    $sel.eq(idx+1).empty().html(data).attr("disabled", false);
                    // select의 옵션이 변경됐을 경우 하위 옵션 disabled
                    if(idx+1 < sel_count) {
                        var idx2 = idx + 1;
                        $frm.find("select.it_option:gt("+idx2+")").val("").attr("disabled", true);
                    }
                }
            );
        } else if((idx + 1) == sel_count) { // 선택옵션처리
            if(val == "")
                return;
            var info = val.split(",");
            // 재고체크
            if(parseInt(info[2]) < 1) {
                alert("선택하신 선택옵션상품은 재고가 부족하여 구매할 수 없습니다.");
                return false;
            }
        }
    });
    $(document).on("click", ".cartopt_cart_btn", function() {
        add_cart(this.form);
    });
    $(document).on("click", ".cartopt_close_btn", function() {
        $(this).closest(".sct_cartop").css("display","none");
        $(this).closest("li.sct_li").find(".sct_btn").css("display", "");
    });
    $(document).on("click", ".btn_wish", function() {
        add_wishitem(this);
    });
});
function add_wishitem(el)
{
    var $el   = $(el);
    var it_id = $el.data("it_id");
    if(!it_id) {
        alert("상품코드가 올바르지 않습니다.");
        return false;
    }
    $.post(
        g5_theme_shop_url + "/ajax.wishupdate.php",
        { it_id: it_id },
        function(error) {
            if(error != "OK") {
                alert(error.replace(/\\n/g, "\n"));
                return false;
            }
            alert("상품을 위시리스트에 담았습니다.");
            return;
        }
    );
}
function add_cart(frm)
{
    var $frm = $(frm);
    var $sel = $frm.find("select.it_option");
    var it_name = $frm.find("input[name^=it_name]").val();
    var it_price = parseInt($frm.find("input[name^=it_price]").val());
    var id = "";
    var value, info, sel_opt, item, price, stock, run_error = false;
    var option = sep = "";
    var count = $sel.size();
    if(count > 0) {
        $sel.each(function(index) {
            value = $(this).val();
            item  = $(this).prev("label").text();
            if(!value) {
                run_error = true;
                return false;
            }
            // 옵션선택정보
            sel_opt = value.split(",")[0];
            if(id == "") {
                id = sel_opt;
            } else {
                id += chr(30)+sel_opt;
                sep = " / ";
            }
            option += sep + item + ":" + sel_opt;
        });
        if(run_error) {
            alert(it_name+"의 "+item+"을(를) 선택해 주십시오.");
            return false;
        }
        price = value[1];
        stock = value[2];
    } else {
        price = 0;
        stock = $frm.find("input[name^=it_stock]").val();
        option = it_name;
    }
    // 금액 음수 체크
    if(it_price + parseInt(price) < 0) {
        alert("구매금액이 음수인 상품은 구매할 수 없습니다.");
        return false;
    }
    // 옵션 선택정보 적용
    $frm.find("input[name^=io_id]").val(id);
    $frm.find("input[name^=io_value]").val(option);
    $frm.find("input[name^=io_price]").val(price);
    $.ajax({
        url: frm.action,
        type: "POST",
        data: $(frm).serialize(),
        dataType: "json",
        async: true,
        cache: false,
        success: function(data, textStatus) {
            if(data.error != "") {
                alert(data.error);
                return false;
            }
            alert("상품을 장바구니에 담았습니다.");
        }
    });
    return false;
}
// php chr() 대응
if(typeof chr == "undefined") {
    function chr(code)
    {
        return String.fromCharCode(code);
    }
}
 

이 질문에 댓글 쓰기 :

답변 1

스크립트에서 반응하는 부분을 체크하면서 확인해 보셔야 할듯 합니다.

제대로 스크립트가 반응하고 있는지 alert 부분을 찍어 보면서 확인해 보세요

답변을 작성하시기 전에 로그인 해주세요.
전체 0
QA 내용 검색
  • 개별 목록 구성 제목 답변작성자조회작성일
  • 질문이 없습니다.

회원로그인

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