I'm creating a shopping cart page that adds info about a product to an array when a button is clicked. I want to be able to search the cart array, and if that product was already added, increase the quantity of it.
So I have something like this: $scope.cartItems = [];
$scope.updateCart = function(product) {
var found = $filter('filter')($scope.cartItems, {title: product.title}, true);
if (found.length) {
//This is where i'm not sure what to do
} else {
$scope.addToCart(product);
};
};
$scope.addToCart = function(product) {
$scope.cartItems.push({
title: product.title,
image: product.image,
thumb: product.thumb,
price: product.price,
id: product.id,
quantity: 1
});
};
});