- Merge request !334Add validation constraint to make order_number not required only in the draft state → (Open) created by vinay.p
- Status changed to Needs review
4 months ago 6:54am 18 September 2024
While trying to create an Order through JSON:API I got an error pushing me to provide the order_number
as part of the request.
After some discussion with mikelutz and mglaman on Slack, the suggested solution was to make the order_number
not required for draft orders and then add a custom validation constraint which marks it required for the other states.
The expectation would be to have the same behavior as if an Order is placed through the site where the order_number
is set by the EventSubscriber to be the same as the order_id
.
Extract of the body of JSON:API POST request:
{
"data": {
"type": "commerce_order--default",
"attributes": {
"mail": "dscl@example.com",
"state": "draft"
},
(...)
}
Extract of the JSON:API error:
(...)
"title": "Unprocessable Entity",
"status": "422",
"detail": "order_number: This value should not be null.",
"source": {
"file": "/var/www/devbrains/pubfactory-d9/web/core/modules/jsonapi/src/Entity/EntityValidationTrait.php",
"line": 59,
"pointer": "/data/attributes/order_number"
},
(...)
Needs review
2.0
Order
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.