I am trying to add a list of products and upsell for these products (1 product may be added multiple times to cart). Using addProduct function i am adding product from available list to an array like this
$scope.addToCartData.push($scope.addproduct[id]);
each product further has an array of upsell products, now in another controller in which i have logic for upsell products, i am incrementing upsell product qty using the following code
$scope.addUpsellPro=function(pid,pos)
{
angular.element(document.querySelector('[ng-controller="ManagerCtrl"]')).scope().addToCartData[pos].upsellsProducts[pid].qty++;
console.log(pos);
}
in here pid is the upsell product id and pos is the index value taken from
addToCartData
but the strange thing happen is it increments qty of upsell products for all same products. e.g. if I have a product PRO1 in addproduct array, this product have up1 and up2 as upsells, now if I push PRO1 two times to the addToCartData array and then tries to increment qty of upsell product of PRO1 at postion 0 (first). it also update upsell products qty at postion 1 :(
