Refactor the loop of ShoppingCart.updateCart