$scope.updateCart = function(item) {
var index;
var items = 0;
var cost = 0;
if (item.ref) {
$scope.selectedMenueItems.push(item);
console.log('updatedd item ' + JSON.stringify($scope.selectedMenueItems));
}
}
$scope.addItem = function(item) {
console.log('item clicked is ' + JSON.stringify(item));
var temp = item;
temp.quantity = 0;
if (item.item_details.item_sub_category.length > 0) {
var itemDetails = item;
var modalInstance = $modal.open({
backdrop: 'static',
keyboard: false,
templateUrl: 'template/itemOptions.html',
controller: 'itemOptionsController',
resolve: {
itemDetails: function() {
return itemDetails;
}
}
});
modalInstance.result.then(
function(result) {
if (result.length > 0) {
temp.totalPrice = temp.originalCost;
temp.ref = [];
angular.forEach(result, function(info) {
if (!info.option_cumpulsory) {
temp.totalPrice += info.option_price;
}
var item = {};
item.id = info._id;
item.name = info.option_name;
item.quantity = info.quantity;
item.option_cumpulsory = info.option_cumpulsory;
item.price = info.option_price;
temp.ref.push(item);
});
temp.quantity += 1;
console.log('item to be added ' + JSON.stringify(temp));
$scope.updateCart(temp);
} else {
temp.quantity = temp.quantity + 1;
$scope.updateCart(temp);
}
},
function(result) {
if (!result) {
temp.quantity = temp.quantity + 1;
$scope.updateCart(temp);
}
}
);
}
}
When adding a new item with different ref options after already pushing an item, the issue arises where the same ref items are copied for both items. How can I make sure duplicate items have different refs?