I have followed instruction on adding new custom document type from shopware docs for 6.4.
The only difference from above example is adding $this->addDocumentBaseConfig($connection, $documentTypeId);
copied from docs for 6.5
New document type show correctly in admin panel but I cannot generate this document. Inside order when I click generate document, app sends request with body
{
"config": {
"custom": {},
"documentNumber": "10004",
"documentComment": "",
"documentDate": "2023-05-09T09:33:38.545Z"
},
"referenced_document_id": null
}
on endpoint POST /api/_action/order/65a3583a9bf543339c12ebf34a04b640/document/proforma
where proforma
is my custom document type
In response I get
{
"errors": [
{
"status": "400",
"code": "DOCUMENT__GENERATION_ERROR",
"title": "Bad Request",
"detail": "Unable to generate document. referencedDocumentId must not be null for documents of type proforma",
"meta": {
"parameters": []
}
}
]
}
Why is that?
When I checked request for other document type, invoice
for example, referencedDocumentId
is set to null
as well but document is generated correctly.
This exception is thrown if your document_base_config
has a set referencedDocumentType
but you don't provide the referenceDocumentId
.
Simply don't set the referenceDocumentType
when creating the base config.
private function addDocumentBaseConfig(Connection $connection, string $documentTypeId): void
{
$defaultConfig = [
'displayPrices' => true,
'displayFooter' => true,
'displayHeader' => true,
// ...
'referencedDocumentType' => self::TYPE, // <= remove this line
];
// ...
}