Change Storage Product In Cart When Seller Updates Product

Hello everyone. For one of my projects, I’ve had to do a shopping cart where a buyer can add a product to their cart which stores in Ionic Storage(cordova-sqlite-storage plugin). I’d like to put a verifying check when the buyer clicks on a button called “PlaceOrder” that the storage items are either updated or deleted from storage based on if the seller has deleted or changed the product name or cost. I wouldn’t want that a buyer can buy an item that doesn’t exist anymore or whose name/price has changed. Since Ionic Storage seems to store for a relatively long time, a buyer may add items to cart in week 1, and then decide to purchase in week 3, when product details may have changed. I have come up with the below code but it is so mammoth I am fearful that it may crash if there are many items in the cart storage. If there are simpler ways to achieve the functionality of deleting or updating products in cart storage, please let me know. Cheers.

placeOrder() {
   let loader = this.loadingCtrl.create({
      content: "Verifying Products..."
    });
    loader.present();
 
    this.storserv.getItems().then((todos) => {
      if (!todos) {
        loader.dismiss();

        return [];
      }
      else if (todos) {
        todos.forEach((item) => {
         firebase.database().ref(`products`).orderByChild('key').equalTo(item.key4)
            .on("value", snapie => {
              if (snapie.exists()) {
                snapie.forEach(snapshot => {
                  const tit = snapshot.val().title;
                  const numb = snapshot.val().cost;
                  if (item.cost != numb || item.title != tit) {
                    let productCount = item.count
                    let productPrice = productCount * parseInt(numb);
                
                    let cartProduct = {
                        count: item.count,
                        totalPrice: productPrice,
                        title: tit,
                        description: item.description,
                        cost: numb,
                        image: item.image,
                        key4: item.key,
                      };
                      this.removeItem(item).then(() => { 
                      this.storserv.updateCarts(cartProduct).then((val) => {
                         loader.dismiss().catch(()=>{});
                        this.presentToast("Product(s) updated!")
                        this.loade();

                      }); 
                    })
                  } else { console.info('NoChange') 
                  loader.dismiss().catch(()=>{});
                }
                })
              } else {

                this.removeItem(item)
                  .then(() => {
                    loader.dismiss().catch(()=>{});
                    this.presentToast("Sorry, product(s) removed due to unavailability!");
                  })
                this.loade();

              }

              return false;
              })
        })
      }
    });
}


loade() {
    let loader = this.loadingCtrl.create({
      content: "Updating Cart..."
    });
    loader.present();
    this.storserv.getItems().then((todos) => {
      if (!todos) {
        loader.dismiss();
        return [];

      }
      else if (todos) {
        this.cartItemsy = todos
        loader.dismiss();
      }

    });
  }


In storserv (Storage Service)

 getItems() {
    let _this = this;
    return this.storage.get('cart').then((v) => {
      return _this.items = JSON.parse(v);
    });
  }


Initial AddToCart Method

addToCart(product) {
    return this.getItems().then(result => {
      if (result) {
        if (!this.containsObject(product, result)) {
          result.push(product);
          return this.storage.set('cart', JSON.stringify(result))
            .then(() => { console.log(result, 'll') });
        } else {
          let index = result.findIndex(x => x.key4 == product.key4);
          let prevQuantity = parseInt(result[index].count);
          product.count = (prevQuantity + product.count);
          let currentPrice = (parseInt(product.totalPrice) * product.count);
          product.totalPrice = currentPrice;
          result.push(product);
          return this.storage.set('cart', JSON.stringify(result))
            .then(() => { console.log(result, '8l') });
        }
      } else {
        return this.storage.set('cart', JSON.stringify([product]))
          .then(() => { console.log(product, '6l') });
      }
    })
  }


containsObject(obj, list): boolean {
    if (!list.length) {
      return false;
    }

    if (obj == null) {
      return false;
    }
    let i;
    for (i = 0; i < list.length; i++) {
      if (list[i].key4 == obj.key4) {
        return true;
      }
    }
    return false;
  }

Anyone have any thoughts? Please help.