-1
I am unable to use the ADDITIONAL function well I’m trying to make a cap that person can add the additional in the items however I’m not getting. I am new in the area of programming and I am developing systems for studies.
module.exports = function Cart(cart) {
this.items = cart.items || {};
this.totalItems = cart.totalItems || 0;
this.totalPrice = cart.totalPrice || 0;
this.add = function(item, id) {
var cartItem = this.items[id];
if (!cartItem) {
cartItem = this.items[id] = {item: item, quantity: 0, price: 0, add: {adicional: null, quantidade: 0, preco:0}};
}
cartItem.quantity++;
cartItem.price = cartItem.item.price * cartItem.quantity;
this.totalItems++;
this.totalPrice += cartItem.item.price;
};
this.adicional = function(item, id){
this.items[id].item.add.adicional = item;
};
this.remove = function(id) {
this.totalItems -= this.items[id].quantity;
this.totalPrice -= this.items[id].price;
delete this.items[id];
};
this.getItems = function() {
var arr = [];
for (var id in this.items) {
arr.push(this.items[id]);
}
return arr;
};
};
And
cart.items
would be what?– LeAndrade
that line
this.items[id].item.add.adicional = item;
It’s really weird, it wouldn’t be something likethis.items[id] = item;
orthis.items[id].adicional = item;
?– Ricardo Pontual