snapjay / ngCart

Really simple shopping cart for AngularJS
http://ngcart.snapjay.com
380 stars 236 forks source link

addItem() does not add? #103

Open lrkwz opened 6 years ago

lrkwz commented 6 years ago

Since https://github.com/snapjay/ngCart/blob/1.0.0/src/ngCart.js#L47 passes relative = false in inCart.setQuantity()

        this.addItem = function (id, name, price, quantity, data) {

            var inCart = this.getItemById(id);

            if (typeof inCart === 'object'){
                //Update quantity of an item if it's already in the cart
                inCart.setQuantity(quantity, false); // <- shoudn't this be TRUE instead?!
            } else {
                var newItem = new ngCartItem(id, name, price, quantity, data);
                this.$cart.items.push(newItem);
                $rootScope.$broadcast('ngCart:itemAdded', newItem);
            }

            $rootScope.$broadcast('ngCart:change', {});
        };

I strongly believe that quantity never get updated when calling ngCart.addItem() twice for the same item.