Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
DocumentRendererConfig example
->
addListener
(
InvoiceOrdersEvent::
class
,
function
DInvoiceOrdersEvent
$event
)
use
(
&
$caughtEvent
)
: void
{
$caughtEvent
=
$event
;
}
)
;
if
(
$beforeRenderHook
instanceof \Closure
)
{
$beforeRenderHook
(
$operationInvoice
,
$this
->
getContainer
(
)
)
;
}
$processedTemplate
=
$this
->invoiceRenderer->
render
(
[
$orderId
=>
$operationInvoice
]
,
$this
->context,
new
DocumentRendererConfig
(
)
)
;
static
::
assertInstanceOf
(
InvoiceOrdersEvent::
class
,
$caughtEvent
)
;
static
::
assertCount
(
1,
$caughtEvent
->
getOperations
(
)
)
;
static
::
assertSame
(
$operationInvoice
,
$caughtEvent
->
getOperations
(
)
[
$orderId
]
?? null
)
;
static
::
assertCount
(
1,
$caughtEvent
->
getOrders
(
)
)
;
$order
=
$caughtEvent
->
getOrders
(
)
->
get
(
$orderId
)
;
static
::
assertNotNull
(
$order
)
;
if
(
$processedTemplate
->
getSuccess
(
)
!==
[
]
)
{
static
::
assertArrayHasKey
(
$orderId
,
$processedTemplate
->
getSuccess
(
)
)
;
$caughtEvent
= null;
$this
->
getContainer
(
)
->
get
(
'event_dispatcher'
)
->
addListener
(
DeliveryNoteOrdersEvent::
class
,
function
DDeliveryNoteOrdersEvent
$event
)
use
(
&
$caughtEvent
)
: void
{
$caughtEvent
=
$event
;
}
)
;
$processedTemplate
=
$this
->deliveryNoteRenderer->
render
(
[
$orderId
=>
$operation
]
,
$this
->context,
new
DocumentRendererConfig
(
)
)
;
static
::
assertInstanceOf
(
DeliveryNoteOrdersEvent::
class
,
$caughtEvent
)
;
static
::
assertCount
(
1,
$caughtEvent
->
getOperations
(
)
)
;
static
::
assertSame
(
$operation
,
$caughtEvent
->
getOperations
(
)
[
$orderId
]
?? null
)
;
static
::
assertCount
(
1,
$caughtEvent
->
getOrders
(
)
)
;
static
::
assertArrayHasKey
(
$orderId
,
$processedTemplate
->
getSuccess
(
)
)
;
$rendered
=
$processedTemplate
->
getSuccess
(
)
[
$orderId
]
;
$order
=
$caughtEvent
->
getOrders
(
)
->
get
(
$orderId
)
;
static
::
assertNotNull
(
$order
)
;
'displayLineItems' => true,
'itemsPerPage' => 10,
'displayFooter' => true,
'displayHeader' => true,
]
,
$invoiceId
)
;
$processedTemplate
=
$this
->deliveryNoteRenderer->
render
(
[
$orderId
=>
$operation
]
,
$this
->context,
new
DocumentRendererConfig
(
)
)
;
static
::
assertArrayHasKey
(
$orderId
,
$processedTemplate
->
getSuccess
(
)
)
;
static
::
assertInstanceOf
(
RenderedDocument::
class
,
$processedTemplate
->
getSuccess
(
)
[
$orderId
]
)
;
$rendered
=
$processedTemplate
->
getSuccess
(
)
[
$orderId
]
;
static
::
assertStringContainsString
(
'<html>',
$rendered
->
getHtml
(
)
)
;
static
::
assertStringContainsString
(
'</html>',
$rendered
->
getHtml
(
)
)
;
$generatorOutput
=
$this
->pdfRenderer->
render
(
$rendered
)
;
$caughtEvent
= null;
$this
->
getContainer
(
)
->
get
(
'event_dispatcher'
)
->
addListener
(
CreditNoteOrdersEvent::
class
,
function
DCreditNoteOrdersEvent
$event
)
use
(
&
$caughtEvent
)
: void
{
$caughtEvent
=
$event
;
}
)
;
$processedTemplate
=
$this
->creditNoteRenderer->
render
(
[
$orderId
=>
$operation
]
,
$this
->context,
new
DocumentRendererConfig
(
)
)
;
static
::
assertInstanceOf
(
CreditNoteOrdersEvent::
class
,
$caughtEvent
)
;
static
::
assertCount
(
1,
$caughtEvent
->
getOperations
(
)
)
;
static
::
assertSame
(
$operation
,
$caughtEvent
->
getOperations
(
)
[
$orderId
]
?? null
)
;
static
::
assertCount
(
1,
$caughtEvent
->
getOrders
(
)
)
;
$order
=
$caughtEvent
->
getOrders
(
)
->
get
(
$orderId
)
;
static
::
assertNotNull
(
$order
)
;
if
(
$errorCallback
)
{
$errorCallback
(
$orderId
,
$processedTemplate
->
getErrors
(
)
)
;
}
$renderedDocument
=
new
RenderedDocument
(
)
;
$renderedDocument
->
setContent
(
$fileBlob
)
;
$renderedDocument
->
setName
(
$fileName
)
;
$renderedDocument
->
setContentType
(
$contentType
)
;
return
$renderedDocument
;
}
public
function
preview
(
string
$documentType
, DocumentGenerateOperation
$operation
, string
$deepLinkCode
, Context
$context
)
: RenderedDocument
{
$config
=
new
DocumentRendererConfig
(
)
;
$config
->deepLinkCode =
$deepLinkCode
;
if
(
!
empty
(
$operation
->
getConfig
(
)
[
'custom'
]
[
'invoiceNumber'
]
)
)
{
$invoiceNumber
=
(string)
$operation
->
getConfig
(
)
[
'custom'
]
[
'invoiceNumber'
]
;
$operation
->
setReferencedDocumentId
(
$this
->
getReferenceId
(
$operation
->
getOrderId
(
)
,
$invoiceNumber
)
)
;
}
$rendered
=
$this
->rendererRegistry->
render
(
$documentType
,
[
$operation
->
getOrderId
(
)
=>
$operation
]
,
$context
,
$config
)
;
if
(
!\
array_key_exists
(
$operation
->
getOrderId
(
)
,
$rendered
->
getSuccess
(
)
)
)
{
if
(
Feature::
isActive
(
'v6.6.0.0'
)
)
{
$caughtEvent
= null;
$this
->
getContainer
(
)
->
get
(
'event_dispatcher'
)
->
addListener
(
StornoOrdersEvent::
class
,
function
DStornoOrdersEvent
$event
)
use
(
&
$caughtEvent
)
: void
{
$caughtEvent
=
$event
;
}
)
;
$processedTemplate
=
$this
->stornoRenderer->
render
(
[
$orderId
=>
$operation
]
,
$this
->context,
new
DocumentRendererConfig
(
)
)
;
static
::
assertInstanceOf
(
StornoOrdersEvent::
class
,
$caughtEvent
)
;
static
::
assertCount
(
1,
$caughtEvent
->
getOperations
(
)
)
;
static
::
assertSame
(
$operation
,
$caughtEvent
->
getOperations
(
)
[
$orderId
]
?? null
)
;
static
::
assertCount
(
1,
$caughtEvent
->
getOrders
(
)
)
;
$order
=
$caughtEvent
->
getOrders
(
)
->
get
(
$orderId
)
;
static
::
assertNotNull
(
$order
)
;
static
::
assertArrayHasKey
(
$orderId
,
$processedTemplate
->
getSuccess
(
)
)
;
$rendered
=
$processedTemplate
->
getSuccess
(
)
[
$orderId
]
;
static
::
assertInstanceOf
(
RenderedDocument::
class
,
$rendered
)
;