XiaoFaye / WooCommerce.NET

A .NET Wrapper for WooCommerce/WordPress REST API
MIT License
393 stars 218 forks source link

On Stock Product update (variances) on first attempt fails - second or third attemp works. - (deserializing) #752

Open BasitBulbulia opened 1 year ago

BasitBulbulia commented 1 year ago

WordPress 6.2.2 WooCommerce 7.8.2 WooCommerce.NET 0.8.6

I have the code below which is in .net vb ; on update I sometimes get this random errror:-There was an error deserializing the object of type WooCommerceNET.WooCommerce.v3.Variation. Encountered unexpected character '<'."

This is my code : ` Dim Allvariation = Await wc.Product.Variations.GetAll(Existproduct.id, dic)

                Dim lp As Short = 0
                Dim lpp As Short = 0

                'sizing variations <------
                Dim NumE3 As Short = 0
                Try

ErrLoop3: For lpp = 0 To SizeMatrixSplitList.Count - 1

                        For lp = 0 To Allvariation.Count - 1

                            Dim size2find As String = Allvariation.ElementAt(lp).permalink
                            size2find = Mid(size2find, InStr(size2find, "size=") + 5, 100)

                            Dim item As String = SizeMatrixSplitList(lpp)

                            If Trim(size2find) = Trim(item) Then
                                ' MsgBox(size2find & "<>" & item)

                                Dim variationID As Int32 = Allvariation.ElementAt(lp).id

                                Dim ExistproductStockVariation = Allvariation.ElementAt(lp).stock_quantity

                                Dim totalstockVariation As Integer

                                If WebInfoUpdate = True Then
                                    totalstockVariation = ExistproductStockVariation + Convert.ToInt32(StockMatrixSplit(lpp) * DocumentUpdate)
                                Else
                                    totalstockVariation = Convert.ToInt32(StockMatrixSplit(lpp))
                                End If

                                If UpdateQuantityOnly = True Then

                                    Await wc.Product.Variations.Update(variationID, New WooCommerceNET.WooCommerce.v3.Variation With {
                                    .manage_stock = True,
                                                                      .stock_quantity = totalstockVariation
                                                                      }, Existproduct.id)

                                Else

                                    If WebInfoUpdate = True And DocumentvvT <> 19 Then

                                        Await wc.Product.Variations.Update(variationID, New WooCommerceNET.WooCommerce.v3.Variation With {
                                        .manage_stock = True,
                                                                      .stock_quantity = totalstockVariation
                                                                      }, Existproduct.id)

                                    Else

                                        Await wc.Product.Variations.Update(variationID, New WooCommerceNET.WooCommerce.v3.Variation With {
                                                                      .regular_price = regular_price,
                                                                      .sale_price = sale_price,
                                                                      .price = sale_price,
                                                                      .manage_stock = True,
                                                                      .stock_quantity = totalstockVariation
                                                                      }, Existproduct.id)

                                    End If
                                End If
                            End If

                        Next lp

                    Next lpp

                Catch ex As Exception
                    If NumE3 < 2 Then
                        NumE3 = NumE3 + 1
                        LstFiles.Items.Add("Re-TRY -(3)--> " & sku & " Tries : " & NumE3)
                        Thread.Sleep(3000)
                        GoTo ErrLoop3
                        'GoTo starttop
                    End If
                    LstFiles.Items.Add("Failed -(3)--> " & sku & " Error : " & ex.Message)                        
                End Try

`