setReferencedDocumentId example

if (empty($invoice)) {
                    throw new DocumentGenerationException('Can not generate storno document because no invoice document exists. OrderId: ' . $operation->getOrderId());
                }

                $documentRefer = json_decode((string) $invoice['config'], true, 512, \JSON_THROW_ON_ERROR);

                $referenceInvoiceNumbers[$orderId] = $documentRefer['documentNumber'];

                $order = $this->getOrder($orderId$invoice['orderVersionId']$context$rendererConfig->deepLinkCode);

                $orders->add($order);
                $operation->setReferencedDocumentId($invoice['id']);
                if ($order->getVersionId()) {
                    $operation->setOrderVersionId($order->getVersionId());
                }
            } catch (\Throwable $exception) {
                $result->addError($operation->getOrderId()$exception);
            }
        }

        // TODO: future implementation (only fetch required data and associations)
        $this->eventDispatcher->dispatch(new StornoOrdersEvent($orders$context$operations));

        
if (empty($invoice)) {
                    throw new DocumentGenerationException('Can not generate credit note document because no invoice document exists. OrderId: ' . $operation->getOrderId());
                }

                $documentRefer = json_decode((string) $invoice['config'], true, 512, \JSON_THROW_ON_ERROR);

                $referenceInvoiceNumbers[$orderId] = $documentRefer['documentNumber'];

                $order = $this->getOrder($orderId$invoice['orderVersionId']$context$rendererConfig->deepLinkCode);

                $orders->add($order);
                $operation->setReferencedDocumentId($invoice['id']);
                if ($order->getVersionId()) {
                    $operation->setOrderVersionId($order->getVersionId());
                }
            } catch (\Throwable $exception) {
                $result->addError($operation->getOrderId()$exception);
            }
        }

        $this->eventDispatcher->dispatch(new CreditNoteOrdersEvent($orders$context$operations));

        foreach ($orders as $order) {
            
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')) {
                throw DocumentException::generationError();
            }

            throw new InvalidOrderException($operation->getOrderId());
        }

        
Home | Imprint | This part of the site doesn't use cookies.