2014-11-25 2 views
0

는 해결 할 수있는 간단한 문제가 될해야하는지에 대한 답을 찾기 위해 광범위하게 here의 GitHub의 페이지, 여기 발견 장바구니가 없으므로 항목을 추가 할 때 장바구니로 보내지는 수량과 함께 최대 수량을 포함하는 사용자 지정 특성과 비교하여 확인할 수 있습니다.simpleCart.js - beforeAdd()로 장바구니에있는 단일 항목의 수량 호출.</p> <p>을 나는 단일 품목의 수량을 얻을 필요가 : 나는 simpleCart 문서를 검색 한

simpleCart.quantity(); 장바구니에있는 모든 항목에 대한 총계를 제공하며 simpleCart.item.quantity();와 동일합니다. 한편, item.get ('quantity')는 제가 카트에 보내는 금액을 알려주지 만 필요한 값은 아닙니다.

여기에 상황에 맞는

if (simpleCart.has(item)) { 
    var mA = item.get('maxamount'); 

    var linkQty = item.get('quantity'); 
    totalquant = (item.quantity() + linkQty); 

    alert('Max amount: '+mA+'\nQty sent to cart: '+linkQty+'\nQty in cart plus qty sent to cart: '+totalquant); 
    if(totalquant > mA){ 
     alert("You can not select more than "+mA+" items of this size!"); 
     return false; 
    } 
} 

나는이 정확한 질문은이 사이트에 존재 알고에 대한 관련 코드이지만, 응답을 받았다 없습니다. 누군가 나를 도울 수 있습니까?

답변

1

나는 당신이 정말로 가깝다고 생각합니다. SimpleCart v3을 사용했습니다.

simpleCart.bind('beforeAdd', function (item) { 
var requestedQuantity = item.get('quantity'); 
var existingItem = simpleCart.has(item); 
if (existingItem) { 
    requestedQuantity += existingItem.get('quantity'); 
} 
if (requestedQuantity > item.get('maxamount')) { 
    alert("You have reached the maximum quantity of this size."); 
    return false; 
} 
});