18.5 C
New York
Tuesday, September 17, 2024

ios – Why after including a product to the cart the simpleButton button just isn’t changed by a quantityView?


I’m engaged on a mission and I want the person to have the ability to click on on the cart button within the order cancellation card and add a product there, after including the product the cart button ought to be changed by a counter, however this doesn’t occur

non-public func addToCart() {
    appVM.showLoadingScreen = true
    
    appVM.cartVM.basketAddProduct(productId: productId) { response in
      appVM.showLoadingScreen = false
      change response {
      case .success(_):
        addedToCart = true
        appVM.objectWillChange.ship()
        
        completion?()
        
        let button = Button(motion: {
          appVM.controllers.setTabBar()
          home windows.switchTo(4)
        }, label: {
          Textual content("Показать")
            .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: "Не удалось добавить товар в корзину")
      }
    }
  }
 non-public var inCart: Bool {
    (appVM.cartVM.merchandise + appVM.cartVM.missingProducts).map({ $0.id }).incorporates(productId) || addedToCart
    //        || addedToCart
  }

  non-public var amount: String {
    guard let product = (appVM.cartVM.merchandise + appVM.cartVM.missingProducts).first(the place: { $0.id == productId }) else {
      return ""
    }
    return product.basket?.format?.amount ?? ""
  }
  
  non-public var availableQuantity: Int {
    guard let product = (appVM.cartVM.merchandise + appVM.cartVM.missingProducts).first(the place: { $0.id == productId }) else {
      return 999
    }
    return 999//product.availableQuantity ?? 999
  }
  
  non-public var buttonWithQuantity: some View {
    ZStack {
      if appVM.cartVM.dataIsLoading {
        shimmering
      } else if addedToCart || inCart{
          quantityView
      } else {
        simpleButton
      }
    }
  }
  
  non-public var shimmering: some View {
    RoundedRectangle(cornerRadius: 4)
      .fill(AppColors.grayText)
      .shimmering()
      .body(width: width, peak: peak)
  }
  
  non-public var quantityView: some View {
    HStack {
      minusButton
      
      Textual content("(amount)")
        .medium(fontSize: 13)
        .foregroundColor(AppColors.black)
        .body(minWidth: 28)
        .withIdentifier("amount.(amount)", in: "CartButtonView")
        .onTapGesture {
          appVM.cartVM.quantityChangingProductId = productId
        }
      
      plusButton
    }
    .body(minWidth: width)
  }
  

appeared by way of every thing very fastidiously, however nonetheless didn’t perceive what the issue was

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles