我正在使用simpleCart(js)将购物车集成到我的WordPress站点中。
我在卖文章,我真的不需要数量,因为显然没有人想购买2个相同的文章,我想防止用户添加超过1个文章到购物车。
所以问题是:如何防止多次添加相同的项目?
我自己找不到解决方案,所以请帮助我(我对任何方法都没意见,只要它有效)!
谢谢!
附言:这篇文章的文档非常少,但是脚本非常轻量级的CLICK HERE FOR LINK
发布于 2011-11-20 02:21:59
在任何人需要的情况下,我已经在128行的.js包中找到了它。
只需将函数更改为以下(这样它就不会向现有项目添加新数量):
if( me.hasItem(newItem) ) {
var foundItem=me.hasItem(newItem);
foundItem.quantity= parseInt(foundItem.quantity,10);
newItem = foundItem;
isNew = false;
} else {
me.items[newItem.id] = newItem;
}
me.update();
me.trigger('afterAdd', [newItem,isNew] );
return newItem;发布于 2012-04-28 01:45:35
使用'beforeAdd‘事件和.hasItem方法:
simpleCart.bind( 'beforeAdd' , function( item ){
// return false if the item is in the cart,
// so it won't be added again
return !simpleCart.hasItem( item );
});https://stackoverflow.com/questions/8167675
复制相似问题