Why the counter may not turn on in the product cancellation card after clicking on adding to cart?

After the user cancels the order, a card of the canceled product appears in front of him, which shows this product and the add to cart button. After clicking on the cart, the counter should turn on, and the product should be added to the cart, but this does not happen. It is added, but the counter does not appear



import SwiftUI
import Shimmer

struct CustomButton: View {
  //    @EnvironmentObject var cartVM: CartVM
  @EnvironmentObject var windows: Windows
  
  var text: String
  var height: Double
  var productId: Int? = nil
  var colorChanging: Bool = false
  var action: () -> Void
  
  var body: some View {
    Button(action: {
      if text == "В корзину" && productId != nil{
        action()
      } else {
        action()
      }
    }) {
      ZStack {
        RoundedRectangle(cornerRadius: 4)
          .fill(!colorChanging ? AppColors.blue : text == "Получить новый код" || text == "Повторить звонок" ? Color("blackEA") : AppColors.lightGray)
        
        Text(text)
          .mediumSFText(fontSize: 13)
          .foregroundColor(!colorChanging ? .white : text == "Получить новый код" || text == "Повторить звонок" ? AppColors.blue : AppColors.darkGray)
      }
    }
    .frame(height: height)
  }
}

struct GrayCustomButton: View {
  var text: String
  var height: Double
  var action: () -> Void
  
  var body: some View {
    Button(action: action) {
      ZStack {
        RoundedRectangle(cornerRadius: 4)
          .fill(AppColors.blue)
          .frame(height: height)
        
        Text(text)
          .mediumSFText(fontSize: 13)
          .foregroundColor(Color.black)
      }
    }
  }
}

struct ActiveCheckCircle: View {
  var body: some View {
    Circle()
      .strokeBorder(AppColors.blue, lineWidth: 5)
      .background(Circle().foregroundColor(Color.white))
      .frame(width: 20, height: 20)
      .padding()
  }
}

struct UnActiveCheckCircle: View {
  var body: some View {
    Circle()
      .strokeBorder(AppColors.darkGray, lineWidth: 1)
      .background(Circle().foregroundColor(Color.white))
      .frame(width: 20, height: 20)
      .padding()
  }
}

struct MyButtonStyle: ButtonStyle {
  public func makeBody(configuration: MyButtonStyle.Configuration) -> some View {
    configuration.label
      .opacity(configuration.isPressed ? 1 : 1)
  }
}


struct IconButton: View {
  var icon: Image
  var width: Double
  var height: Double
  var action: () -> Void
  
  var body: some View {
    Button(action: action) {
      ZStack {
        RoundedRectangle(cornerRadius: 4)
          .fill(AppColors.lightGray)
          .frame(width: width, height: height)
        
        icon
      }
    }
  }
}

enum AddToCartButtonTypes {
  case simple
  case withQuantity
}

struct AddToCartButton: View {
  @EnvironmentObject private var appVM: AppViewModel
  @EnvironmentObject private var windows: Windows
  
  var productId: Int
  var screen: ECommerceScreenCustom
  private var type: AddToCartButtonTypes
  private var width: CGFloat
  private var height: CGFloat
  private var plusMinusButtonsWidth: CGFloat = 32
  private var plusMinusButtonsHeight: CGFloat = 32
  private var label: String
  private var completion: (()->())?
  @State private var addedToCart = false
  
  // 108 - 32
  // 95 - 32 (деталка товара над таббаром)
  
  init(productId: String, screen: ECommerceScreenCustom = DefaultECommerceScreen(), type: AddToCartButtonTypes = .simple, label: String = "В корзину", width: CGFloat = 108, height: CGFloat = 32, completion: @escaping() -> () = {}) {
    self.productId = Int(productId) ?? 0
    self.type = type
    self.width = width
    self.height = height
    self.label = label
    self.completion = completion
    self.screen = screen
  }
  
  init(productId: Int, screen: ECommerceScreenCustom = DefaultECommerceScreen(), type: AddToCartButtonTypes = .withQuantity, label: String = "В корзину", width: CGFloat = 108, height: CGFloat = 32, plusMinusButtonsWidth: CGFloat = 32, plusMinusButtonsHeight: CGFloat = 32, completion: @escaping() -> () = {}) {
    self.productId = productId
    self.type = type
    self.width = width
    self.height = height
    self.label = label
    self.plusMinusButtonsWidth = plusMinusButtonsWidth
    self.plusMinusButtonsHeight = plusMinusButtonsHeight
    self.completion = completion
    self.screen = screen
  }
  
  var body: some View {
    Group {
      switch type {
      case .simple:
        simpleButton
      case .withQuantity:
        buttonWithQuantity
      }
    }
    .onAppear {
      addedToCart = inCart
    }
  }
  
  private var simpleButton: some View {
    ZStack {
      RoundedRectangle(cornerRadius: 4)
        .fill(AppColors.blue)
        .frame(width: width, height: height)
      
      Text(label)
        .medium(fontSize: 13)
        .foregroundColor(Color.white)
    }
    .contentShape(Rectangle())
    .onTapGesture {
      addToCart()
    }
  }
  
  private func addToCart() {
    appVM.showLoadingScreen = true
    
    appVM.cartVM.basketAddProduct(productId: productId) { response in
      appVM.showLoadingScreen = false
      switch response {
      case .success(_):
        addedToCart = true
        
        completion?()
        
        let button = Button(action: {
          appVM.controllers.setTabBar()
          windows.switchTo(4)
        }, label: {
          Text("Показать")
            .medium(fontSize: 13)
            .foregroundColor(AppColors.blue)
        })
        
        // Тост с переходом в корзину
        appVM.showToast(withMessage: "Товар добавлен в корзину", toastButton: AnyView(button))
        
        appVM.cartVM.getProducts(withLoadingScreen: false, fiasId: appVM.selectedCity.fiasID) {_ in
          sendAnalytics()
        }
      case .failure(_):
        appVM.showToast(withMessage: "Не удалось добавить товар в корзину")
      }
    }
  }
  
  private func sendAnalytics() {
    guard let product = (appVM.cartVM.products + appVM.cartVM.missingProducts).first(where: { $0.id == productId }) else { return }
    
    var parameters = [String: Any]()
    parameters["AnalyticsParameterValue"] = (product.prices?.additionalPrice ?? 0.0) * (product.basket?.quantity ?? 0.0)
    parameters["AnalyticsParameterPrice"] = product.prices?.price
    parameters["AnalyticsParameterCurrency"] = "₽"
    parameters["AnalyticsParameterItemID"] = productId
    parameters["AnalyticsParameterItemName"] = product.title
    parameters["AnalyticsParameterQuantity"] = quantity
    AnalyticsManager.sharedInstance.sendAddingProductToBasketEvent(with: parameters)
    
    AppMetricaECommerceCartChagesHelper().addToCartEvent(screen: DefaultECommerceScreen(), product: product, count: 1)
  }
  
  // BUTTON WITH QUANTITY
  private var inCart: Bool {
    (appVM.cartVM.products + appVM.cartVM.missingProducts).map({ $0.id }).contains(productId)
    //        || addedToCart
  }
  
  private var quantity: String {
    guard let product = (appVM.cartVM.products + appVM.cartVM.missingProducts).first(where: { $0.id == productId }) else {
      return ""
    }
    return product.basket?.format?.quantity ?? ""
  }
  
  private var availableQuantity: Int {
    guard let product = (appVM.cartVM.products + appVM.cartVM.missingProducts).first(where: { $0.id == productId }) else {
      return 999
    }
    return 999//product.availableQuantity ?? 999
  }
  
  private var buttonWithQuantity: some View {
    ZStack {
      if appVM.cartVM.dataIsLoading {
        shimmering
      } else if inCart {
        quantityView
      } else {
        simpleButton
      }
    }
  }
  
  private var shimmering: some View {
    RoundedRectangle(cornerRadius: 4)
      .fill(AppColors.grayText)
      .shimmering()
      .frame(width: width, height: height)
  }
  
  private var quantityView: some View {
    HStack {
      minusButton
      
      Text("(quantity)")
        .medium(fontSize: 13)
        .foregroundColor(AppColors.black)
        .frame(minWidth: 28)
        .withIdentifier("quantity.(quantity)", in: "CartButtonView")
        .onTapGesture {
          appVM.cartVM.quantityChangingProductId = productId
        }
      
      plusButton
    }
    .frame(minWidth: width)
  }
  
  private var plusButton: some View {
    ZStack {
      RoundedRectangle(cornerRadius: 4)
        .fill(Color("primary200"))
      
      Text("+")
        .bold(fontSize: 16)
        .foregroundColor(AppColors.blue)
    }
    .frame(width: plusMinusButtonsWidth, height: plusMinusButtonsHeight)
    .withIdentifier("plusButton", in: "CartButtonView")
    .contentShape(Rectangle())
    .onTapGesture {
      appVM.cartVM.changedProductId = productId
      for index in 0..<appVM.cartVM.products.count {
        if productId == appVM.cartVM.products[index].id {
          let currentQuantity = appVM.cartVM.products[index].basket?.quantity ?? 0.0
          let productAvailability = appVM.cartVM.products[index].basket?.isMaxQuantity
          
          if currentQuantity < 999 && !productAvailability! {
            appVM.cartVM.products[index].basket?.quantity += 1.0
            appVM.cartVM.changedQuantity = 1 //Int(appVM.cartVM.products[index].basket?.quantity ?? 0.0)
          } else {
            AppState.showToast(withMessage: "Больше нет в наличии")
          }
          break
        }
      }
    }
  }
  
  private var minusButton: some View {
    ZStack {
      RoundedRectangle(cornerRadius: 4)
        .fill(Color("primary200"))
      
      Text("-")
        .bold(fontSize: 16)
        .foregroundColor(AppColors.blue)
    }
    .frame(width: plusMinusButtonsWidth, height: plusMinusButtonsHeight)
    .withIdentifier("minusButton", in: "CartButtonView")
    .contentShape(Rectangle())
    .onTapGesture {
      appVM.cartVM.changedProductId = productId
      for index in 0..<appVM.cartVM.products.count {
        if productId == appVM.cartVM.products[index].id {
          if appVM.cartVM.products[index].basket?.quantity ?? 0.0 > 0 {
            appVM.cartVM.products[index].basket?.quantity -= 1.0
            appVM.cartVM.changedQuantity = -1//Int(appVM.cartVM.products[index].basket?.quantity ?? 0.0)
            if appVM.cartVM.products[index].basket?.quantity == 0 {
              addedToCart = false
            }
          }
          break
        }
      }
    }
  }
}

I looked through everything carefully, but I still do not understand what the problem could be

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật