我正在为电子商店设置购物车。我正在尝试从显示的产品中获取数据以创建订单清单。购物车是一个具有3个equals方法的对象,用于添加数量,名称和价格。但是只有一项工作。另外两个覆盖数据。
我要库存的数据是字符串。
var Cart = function () {
this.cartListQte = {}
this.products_names = {}
this.products_prices = {}
}
//班级
Cart.prototype = {
//properties
'cartListQte': {},
'products_names': {},
'products_prices': {},
//methods
//setter getter
setCartListQte: function (cartListQte) {
this.cartListQte = cartListQte;
},
getCartListQte: function () {
return this.cartListQte;
},
setProducts_names: function (products_names) {
this.products_names = products_names;
},
getProducts_names: function () {
return this.products_names;
},
setProducts_prices: function (products_prices) {
this.products_prices = products_prices;
},
getProducts_prices: function () {
return this.products_prices;
},
//"push" new product
pushed: function (productId,Qty){
this.cartListQte[parseInt(productId)]= parseInt(Qty);
},
pushName: function (productId,nm){
this.products_names[parseInt(productId)]= nm;
},
pushPrice: function (productId,prx){
this.products_prices[parseInt(productId)]= parseInt(prx);
}
}
// gestion du panier
函数addProductToCart(事件){
//nouveau panier
var cart = new Cart;
//on récupère le panier déjà enregisté
var curentCart = JSON.parse(localStorage.getItem('panier'));
//si il existe, on le manipule
if(curentCart != null){
cart.cartListQte = curentCart.cartListQte;
}
//récupération des nouvelles données à enregistrer
var id = $(this).attr('productid');
var quantity = $("[productIdQte="+id+"]").val();
console.log(quantity);
一只萌萌小番薯
相关分类