首页 > 解决方案 > 当产品从购物车中删除时如何更新购物车总摘要

问题描述

我是 Ionic 的新手,目前正在开发一个电子商务应用程序。我已成功显示添加到购物车页面的产品,现在需要实现从总摘要中扣除相关金额的逻辑,如果产品从购物车中删除。

这是我的购物车.ts

removeFromCart(index,item){
    this.totalPrice = 0;
    let sumTotal = 0;
    let price = item.price;
    let qty = item.quantity
    sumTotal = price * qty;
    this.cartData.splice(index,1);
    let pId = item.id;
    this.storage.remove(`product_${pId}`).then(()=>{
    this.totalPrice -= sumTotal
    });
  }

这总结了购物车中的产品

calculatePrice(){
      this.totalPrice = 0;
      let tempPrice = 0;
      this.baseProducts.forEach((product) => {
      tempPrice = product.price * product.quantity;
      this.totalPrice += tempPrice
      });
    return this.totalPrice;
  } 

标签: javascript

解决方案


推荐阅读