commercetools / commercetools-jvm-sdk

The e-commerce SDK from commercetools running on the Java virtual machine.
https://commercetools.github.io/commercetools-jvm-sdk/apidocs/index.html
Other
62 stars 40 forks source link

Cart: reference expansion for paymentInfo not working #1286

Closed fhaertig closed 7 years ago

fhaertig commented 7 years ago

Hi,

When querying for a cart, I'm trying to resolve payment references belonging to this cart by adding it as expansion path to the query. However, it seems to take no effect. This is true for sunrise-java v0.14.0 (which is using the sphere-sdk v1.5.0), but you can easily test it with the playground, too. The paths I tried:

paymentInfo paymentInfo.payments payments

lauraluiz commented 7 years ago

Hi @fhaertig ,

What we see from your paths is that they are not correct for array types. You would need to do paymentInfo.payments[*] to make it work (as explained in http://dev.commercetools.com/http-api.html#reference-expansion)

But you don't need to write it yourself with the JVM SDK, you can use the provided Query DSL for that and just write:

.plusExpansionPaths(m -> m.paymentInfo().payments())
fhaertig commented 7 years ago

Ok thanks, got it working with the playground. However, we already use the DSL you mentioned with sunrise (sdk v1.5.0) and the expansion still doesn't happen. I will check if its an issue with sunrise and will come back to you.

lauraluiz commented 7 years ago

Ok, let me know. In the JVM SDK it should work fine because there is an integration test that covers the reference expansion case: https://github.com/commercetools/commercetools-jvm-sdk/blob/master/commercetools-models/src/test/java/io/sphere/sdk/carts/commands/CartUpdateCommandIntegrationTest.java#L449-L455

fhaertig commented 7 years ago

After some debugging we found the issue in our code, the sdk and sunrise (e.g. the hooks) are working well. We execute a CartUpdateCommand first and then expect the returned updated Cart to contain the expanded payments. This is obviously not the case for UpdateCommands. I guess there is no way of changing that behaviour? Otherwise we need to query for the Cart again.

lauraluiz commented 7 years ago

@fhaertig actually the reference expansion should be working for cart updates too. We tried to expand the payment references right after adding some payment info and it worked fine via Impex. Moreover the link to the code I wrote before (https://github.com/commercetools/commercetools-jvm-sdk/blob/master/commercetools-models/src/test/java/io/sphere/sdk/carts/commands/CartUpdateCommandIntegrationTest.java#L449-L455) is exactly doing that: adding a payment and expanding the returned cart's payment reference.

What is the update action you are using? I don't think it should matter, but let's try to reproduce the problem with the exact context :)

fhaertig commented 7 years ago

Sorry, I missed that in the test :( I didn't realized you could provide expansion paths to an UpdateCommand. It is working as expected, thank you very much for the help and time!