Don't Add Product if Product is already in localStorage

I have a shopping cart and I only want the products to be set if they don’t already exist in localStorage. If the product is already in localStorage, then no new product should be added. Then I need to update the quantity if the item is already set. The code that I have so far sets the product even if the product already exists and it doesn’t update the quantity.

public onSubmit(id, thumbnail, quantity, product_name, product_price){

var data = {

  var retrieverObject = localStorage.getItem('items');
  var retrieveObject = JSON.parse(retrieverObject);
retrieveObject.forEach(el => {
   if ( == id){
   this.quantity += quantity;
   } else {
   localStorage.setItem(this.storageKey, JSON.stringify(this.items));

A post was merged into an existing topic: Cannot read property ‘storageKey’ of undefined

Since all your posts lately are related to the same project, I have merged this one with the previously posted topic to attempt to keep things in the same topic.

You can continue to add to the this topic by replying and asking your new questions.

Thank you for helping to keep our forum more tidy.