XiaoFaye / WooCommerce.NET

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

SerializationException: The value "parent" cannot be parsed as a type "Boolean" #722

Closed dartrax closed 1 year ago

dartrax commented 1 year ago

This works:

Dim p = Await Woo.Product.GetAll(New Dictionary(Of String, String) From {{"slug", "my-product-slug"}})
Process.Start(p.First.permalink)

This does not work:

Dim p = Await Woo.Product.GetAll(New Dictionary(Of String, String) From {{"sku", "12345678"}})
Process.Start(p.First.permalink)

In my test both calls to GetAll should deliver the same product (my-product-slug is the slug of the product with the sku 12345678)

The error is:

System.Runtime.Serialization.SerializationException: "Error deserializing object "of type System.Collections.Generic.List`1[[WooCommerceNET.WooCommerce.v3.Product, WooCommerce.NET, Version=0.8.4.0, Culture=neutral, PublicKeyToken=ff41d0b6c937438d]]". The value "parent" cannot be parsed as type "Boolean"."

XmlException: the value "parent" cannot be parsed as type "Boolean".

FormatException: The string 'parent' not a valid Boolean value.
dartrax commented 1 year ago

Thanks for your ongoing development of this library! This bug is still present in version 0.8.5

XiaoFaye commented 1 year ago

I don't get this error on local testing, do you mind uploading the returned json details so I can check?

dartrax commented 1 year ago

Thanks for looking into it. I've uploaded only an excerpt of the json, please let me know if you need the whole thing. I believe this is the culprit:

... 
"tax_status":"taxable","tax_class":"","manage_stock":"parent","stock_quantity":12,"backorders":"no",
...

So manage_stock isn't boolean, it has the value "parent", probably because the SKU I'm requesting is a product variant which shares stock with the parent:

image

The reason why it works using the product slug instead of SKU is probably because the product slug refers to the parent while the SKU refers to a child variant of that parent.

Mattoia90 commented 1 year ago

I have the same problem with Variation products. When I use Postman I see < "manage_stock":"parent" > but in the class product is typed: bool?

XiaoFaye commented 1 year ago

It's defined as bool in WC's document, however when in variation products, it could be a string with value "parent". Will fix this in the next version.

XiaoFaye commented 1 year ago

@dartrax This is fixed in version 0.8.6.

dartrax commented 1 year ago

Perfect! Confirming it's fixed now.