Error while creating a cart with CustomLineItems
Opened this issue · 2 comments
While I try to create a cart with the following JSON
{
"currency":"EUR",
"taxMode":"Disabled",
"customLineItems":[
{
"name":{
"en":"Test"
},
"quantity":40,
"money":{
"currencyCode":"EUR",
"centAmount":30
},
"slug":"test",
"custom":{
"type":{
"key":"custom-line-item-custom-fields"
},
"fields":{
"ProductId":"123",
"PapId":"456"
}
}
}
]
}
The cart gets created as this is a valid JSON. The response returned by the commercetools is
{
"type": "Cart",
"id": "2f002000-261e-41ac-afc3-2a0a9ab5e4d9",
"version": 1,
"createdAt": "2017-06-07T09:41:16.912Z",
"lastModifiedAt": "2017-06-07T09:41:16.912Z",
"lineItems": [],
"cartState": "Active",
"totalPrice": {
"currencyCode": "EUR",
"centAmount": 1200
},
"customLineItems": [
{
"totalPrice": {
"currencyCode": "EUR",
"centAmount": 1200
},
"id": "94cd3448-7db5-4127-b680-8c590c1f5a87",
"name": {
"en": "Test"
},
"money": {
"currencyCode": "EUR",
"centAmount": 30
},
"slug": "test",
"quantity": 40,
"discountedPricePerQuantity": [],
"state": [
{
"quantity": 40,
"state": {
"typeId": "state",
"id": "936c92bd-790f-4de5-9b4a-747401275f32"
}
}
],
"custom": {
"type": {
"typeId": "type",
"id": "26233599-7464-4962-8f76-019deea0508c"
},
"fields": {
"ProductId": "123",
"PapId": "456"
}
}
}
],
"discountCodes": [],
"inventoryMode": "None",
"taxMode": "Disabled",
"taxRoundingMode": "HalfEven",
"refusedGifts": []
}
While the cart gets created , the sdk throws an exception while trying to parse the JSON returned by the commercetools platform. The exception returned is
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot convert null to 'int' because it is a non-nullable value type'
This exception is caused by the dynamic assignment of null to the the property 'Version' of the class State
Also note that in the response JSON above, CommerceTools platform does not return a version for the 'state' property of the 'customLineItem'. Only the 'typeId' and the 'id' is returned.
@brajivbala Thank you for adding the new test methods. Regarding your change to State.cs, rather than defaulting the Version property to 0 when not available, I have changed the data type of the Version property from int to int?. This keeps the null handling consistent with the rest of the SDK.
@jhumber Sounds good to me. Thanks for accepting the PR !