If updating\creating the billing\shipping profile via the endpoint provided at /jsonapi/checkout/${order.uuid} there is no check for the validity of the address.
The case we noticed is with the postal code: if some user has insert a combination of administrative_area and postal_code not validated in the backend, thus the relative order address is not actually updated.
The API however returns a 200 code, so there's no way in the front-end to know that actually the order is without an address!
Example of a payload which has a incorrect postal code:
{
data: {
type: "commerce_order--default",
id: "ffa590d4-9e33-49ba-b9f5-dd82da5fda3e",
attributes: {
billing_information: {
address_line1: "test",
address_line2: "1",
administrative_area: "MC",
country_code: "IT",
family_name: "name",
given_name: "surname",
locality: "Locality",
organization: "organization",
postal_code: "6201011", // not valid
},
shipping_information: {
// …
},
data: {
copy_to_address_book: true,
address_book_profile_id: 91
}
},
// ...
}
}
Comments
Comment #2
giuseppe87 commentedComment #3
jsacksick commentedIndeed, that is because
AddressDataDefinitiondoesn't implement thegetConstraints()method (unlike AddressItem).I had a closer look at the code, and I'm now wondering why we're not simply using the AddressItem here in OrderProfile... Attaching a patch doing that... That fixes validation. Some tests might fail though....
The weird part is that we have the following comment in our tests:
But I don't think we're actually expecting that error in the test (since there's no validation happening anyway).
Let's see which tests are failing with the attached patch.
Comment #4
jsacksick commentedAlso, we're partially updating addresses on a project I'm working on (for example, simply updating the postal code), and I'm now getting errors due to a missing first/last name.
So as soon as this is in, the field configuration must be updated to make certain fields optional otherwise this would start failing.
Comment #6
jsacksick commentedI fixed most of the tests failures (there will be one or two remaining I think), but also updated one of the tests to check for the error.
Let's see what failures are remaining.
Comment #7
jsacksick commentedComment #9
jsacksick commentedComment #10
jsacksick commentedThis was added to a project I'm working on, and partial address updates weren't allowed through the API anymore, this needs to be investigated.
Comment #11
dobe commented@jsacksick I am trying to get the shipping address and billing address to update a profile I select using the api instead of creating new entries... How do I pass those parameters? Seems like everything I have tried just creates new entries.
Thank you!
-Jesse