commercetools / commercetools-dotnet-core-sdk

The e-commerce SDK from commercetools running on the .NET Core platform
https://docs.commercetools.com/sdk/dotnet-sdk#net-core-sdk
Apache License 2.0
10 stars 5 forks source link

Query to products does not resolves attributes correctly #192

Closed codewode closed 3 years ago

codewode commented 3 years ago

while trying to fetch products I assume that product attributes and nested attributes defined in product types are automatically resolved/deserialized. However, I get null value

To Reproduce return (from p in client.Query<Product>().ToList() select p).ToList<Product>();

Expected behavior attribute values should correctly be resolved

Actual behavior

{
    "masterVariant":{
        "id":1,
        "sku":"somesku",
        "key":"somekey",
        "prices":[],
        "attributes":[
            {
                "name":"attr1",
                "jsonValue":null
            },
            {
                "name":"attr2",
                "jsonValue":null
            }
        ]
    }
}

Stack information:

Additional context Using the same call directly from the postman resolves the values correctly.

jenschude commented 3 years ago

For performance reasons we had to remove the generic jsonValue with 1.0.3 and it will now only return null all the time. See https://github.com/commercetools/commercetools-dotnet-core-sdk/pull/152

but nevertheless Value should hold the correct deserialized attribute

codewode commented 3 years ago

so I am including Product class from the namespace commercetools.Sdk.Domain, shall I switch to a different Nuget package to have the property "Value" instead of "jsonValue" or shall I downgrade the version of commercetools.Sdk.All? or could you please refer me to some sample implementation. Thanks

codewode commented 3 years ago

ok, I have found a way to extract the attributes, as an example below. Really a long way to access it and i have not found any documentation on that.


var value = (from p in client.Query<Product>().ToList() select p.MasterData.Current.MasterVariant.Attributes.First<Attribute>().ToNumberAttribute().Value).First();```