Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BasitBulbulia opened this issue Jul 15, 2023 · 0 comments

Comments

@BasitBulbulia
Copy link

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

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant