#[Route(path: '/store-api/document/download/{documentId}/{deepLinkCode}', name: 'store-api.document.download', methods: ['GET', 'POST'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true, '_entity' => 'document'])]
public function download(string
$documentId, Request
$request, SalesChannelContext
$context, string
$deepLinkCode = ''
): Response
{ if ($context->
getCustomer() === null
|| ($context->
getCustomer()->
getGuest() &&
$deepLinkCode === ''
)) { throw CartException::
customerNotLoggedIn();
} $download =
$request->query->
getBoolean('download'
);
$document =
$this->documentGenerator->
readDocument($documentId,
$context->
getContext(),
$deepLinkCode);
if ($document === null
) { return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT
);
} return $this->
createResponse( $document->
getName(),
$document->
getContent(),
$download,
$document->
getContentType() );
}