0

我已经搜索了 simpleCart 文档,在这里找到了 github 页面,并在这里广泛地找到了一个应该是一个简单问题的答案:

我需要获取购物车中单个商品的数量,因此我可以对照包含最大数量的自定义属性以及添加商品时发送到购物车的数量来检查它。

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;
    }
}

我知道这个网站上存在这个确切的问题,但没有收到任何回复。请问有人可以帮我吗?

4

1 回答 1

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;
}
});
于 2014-12-21T06:41:32.333 回答