title: Data not properly stored in shopping cart
body: <ul>
  <li>I'm trying to get another service and that works pretty much fine,
  but the problem is, how to properly implement the logic to generate
  the cart items correctly and I want to increase quantity of cart by
  one on every function call, but as it seems it doesn't work on that
  way.</li>
  <li>In <code>Postman</code> I'm always getting the ID of selected data, that's the thing I want.</li>
  <li>So how to generate  <code>totalQty</code> variable to increasingly
  grow by 1 every time the function is called?</li>
  </ul>
  <p>Here is retrieving information through another service and trying to fit it into an existing function <code>AddProduct()</code>.</p>
  <pre><code>app.get('/add-to-cart/:id', async (req, res) =&gt; {
    try {
      let id = req.params.id;
      let cart = new Cart(req.body.cart ? req.body.cart : {});
  
      const { data } = await axios.get('http://localhost:4200/products');
      const singleProduct = await data.find((product) =&gt; product._id === id)
      
      cart.addProduct(singleProduct, singleProduct._id);
      
      req.body.cart = cart;
  
      res.redirect('/');
      console.log(req.body.cart);
    } 
    
    catch (error){
      console.log(error)
    }
    
  });
  </code></pre>
  <p>And here is the adding cart logic:</p>
  <pre><code>module.exports = function Cart(oldCart) {
      this.productItems = oldCart.productItems || {};
      this.totalQty = oldCart.totalQty || oldCart.totalQty==0.00;
      this.totalPrice = oldCart.totalPrice || oldCart.totalPrice==0.00;
     
      this.addProduct = function(item, id) {
          let storedItem = this.productItems;
          storedItem = this.productItems = {item: item, qty: 0, price: 0};
          
          if (!storedItem){
              storedItem = this.productItems = {item: item, qty: 0, price: 0};
              console.log(&quot;stored is empty&quot;)
          }
          else{
          
          console.log(&quot;Stored item full!&quot;)
          storedItem = this.productItems = {item: item, qty: storedItem.qty, price: storedItem.price}
  
          storedItem.qty++;
          storedItem.price = storedItem.item.price * storedItem.qty;
          
          this.totalQty ++;
          this.totalPrice += storedItem.price;
          
      }
      }
  
      this.generateArray = function () {
          let arr = [];
          for (let id in this.productItems) {
              arr.push(this.productItems);
          }
          return arr;
      }};
  </code></pre>
  <p>This is what do I get with <code>console.log</code></p>
  <p><a href="https://i.stack.imgur.com/LL7N3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LL7N3.png" alt="enter image description here" /></a></p>