getDeepLinkCode example



    public function testPreview(): void
    {
        $cart = $this->generateDemoCart(2);
        $orderId = $this->persistCart($cart);

        /** @var OrderEntity $order */
        $order = $this->orderRepository->search(new Criteria([$orderId])$this->context)->get($orderId);
        static::assertNotNull($order);

        $endpoint = sprintf('/api/_action/order/%s/%s/document/invoice/preview', Uuid::randomHex()$order->getDeepLinkCode());
        $this->getBrowser()->request('GET', $endpoint);

        static::assertEquals($this->getBrowser()->getResponse()->getStatusCode(), Response::HTTP_NOT_FOUND);
        $response = json_decode((string) $this->getBrowser()->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertNotEmpty($response['errors']);
        if (!Feature::isActive('v6.6.0.0')) {
            static::assertEquals('CHECKOUT__INVALID_ORDER_ID', $response['errors'][0]['code']);
        } else {
            static::assertEquals('DOCUMENT__GENERATION_ERROR', $response['errors'][0]['code']);
        }

        

        $errors = [];

        foreach ($this->errors as $orderId => $error) {
            $errors[$orderId] = (new ErrorResponseFactory())->getErrorsFromException($error);
        }

        return [
            'data' => $this->success->map(fn (DocumentIdStruct $documentIdStruct) => [
                'documentId' => $documentIdStruct->getId(),
                'documentMediaId' => $documentIdStruct->getMediaId(),
                'documentDeepLink' => $documentIdStruct->getDeepLinkCode(),
            ]),
            'errors' => $errors,
        ];
    }
}
public function testLoadWithReferenceDocumentId(): void
    {
        $cart = $this->generateDemoCart(2);
        $orderId = $this->persistCart($cart);

        // Create two documents, the one with passed referenceInvoiceId will be returned         $invoiceStruct = $this->createDocument(InvoiceRenderer::TYPE, $orderId[]$this->context)->first();
        static::assertNotNull($invoiceStruct);
        $this->createDocument(InvoiceRenderer::TYPE, $orderId[]$this->context)->first();

        $invoice = $this->referenceInvoiceLoader->load($orderId$invoiceStruct->getId()$invoiceStruct->getDeepLinkCode());

        static::assertEquals($invoiceStruct->getId()$invoice['id']);
        static::assertEquals($orderId$invoice['orderId']);
        static::assertSame(Defaults::LIVE_VERSION, $invoice['orderVersionId']);
        static::assertNotEmpty($invoice['config']);
    }
}
$mediaId = $context->scope(Context::SYSTEM_SCOPE, fn (Context $context): string => $this->mediaService->saveMediaFile($mediaFile$fileName$context, 'document'));

        $this->connection->executeStatement(
            'UPDATE `document` SET `updated_at` = :now, `document_media_file_id` = :mediaId WHERE `id` = :id',
            [
                'id' => Uuid::fromHexToBytes($documentId),
                'mediaId' => Uuid::fromHexToBytes($mediaId),
                'now' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ],
        );

        return new DocumentIdStruct($documentId$document->getDeepLinkCode()$mediaId);
    }

    /** * @param array<mixed> $records */
    private function writeRecords(array $records, Context $context): void
    {
        if (empty($records)) {
            return;
        }

        

        $documentIdStruct = $this->documentGenerator->upload(
            $documentId,
            $context,
            $request
        );

        return new JsonResponse(
            [
                'documentId' => $documentIdStruct->getId(),
                'documentMediaId' => $documentIdStruct->getMediaId(),
                'documentDeepLink' => $documentIdStruct->getDeepLinkCode(),
            ]
        );
    }
}
$documentIdStruct = $this->getContainer()->get(DocumentGenerator::class)->upload(
            $document->getId(),
            $context,
            $request
        );

        $browser = $this->login('customer@example.com');

        $browser->request(
            'GET',
            $_SERVER['APP_URL'] . '/account/order/document/' . $documentIdStruct->getId() . '/' . $documentIdStruct->getDeepLinkCode(),
            $this->tokenize('frontend.account.order.single.document', [])
        );

        $response = $browser->getResponse();

        static::assertEquals(200, $response->getStatusCode());
        static::assertEquals($expectedFileContent$response->getContent());
        static::assertEquals($expectedContentType$response->headers->get('content-type'));

        // Customer are unable to view the document without valid deepLinkCode         $browser->request(
            
$order = $this->createCustomerWithOrder();

        $controller = new AccountOrderPageLoader(
            $this->createMock(GenericPageLoader::class),
            $this->createMock(EventDispatcher::class),
            $orderRoute,
            $this->createMock(AccountService::class),
        );

        $controller->load(new Request([
            'deepLinkCode' => $order->getDeepLinkCode(),
            'email' => 'orderTest@example.com',
            'zipcode' => '12345',
        ])$this->salesChannelContext);
    }

    public function testAccountOrderRateLimit(): void
    {
        $order = $this->createCustomerWithOrder();

        for ($i = 0; $i <= 10; ++$i) {
            $this->browser->request(
                
static::assertNotNull($deliveries);
        $delivery = $deliveries->first();
        static::assertNotNull($delivery);
        $orderDeliveryId = $delivery->getId();

        $domain = 'http://shopware.' . Uuid::randomHex();
        $this->setDomainForSalesChannel($domain, Defaults::LANGUAGE_SYSTEM);

        /** @var EventDispatcher $dispatcher */
        $dispatcher = $this->getContainer()->get('event_dispatcher');

        $url = $domain . '/account/order/' . $order->getDeepLinkCode();
        $phpunit = $this;
        $eventDidRun = false;
        $listenerClosure = function DMailSentEvent $event) use (&$eventDidRun$phpunit$url): void {
            $phpunit->assertStringContainsString('The new status is as follows: Cancelled.', $event->getContents()['text/html']);
            $phpunit->assertStringContainsString($url$event->getContents()['text/html']);
            $eventDidRun = true;
        };

        $this->addEventListener($dispatcher, MailSentEvent::class$listenerClosure);

        $this->orderService->orderDeliveryStateTransition(
            
 else {
            $this->expectException(DocumentException::class);
        }

        /** @var OrderEntity $order */
        $order = $this->getContainer()->get('order.repository')->search(new Criteria([$this->orderId])$this->context)->first();

        $operation = new DocumentGenerateOperation($this->orderId);
        $operation->assign([
            'preview' => true,
        ]);
        $documentStruct = $this->documentGenerator->preview(InvoiceRenderer::TYPE, $operation$order->getDeepLinkCode() ?? '', $this->context);

        static::assertNotEmpty($documentStruct->getContent());

        $operation = new DocumentGenerateOperation(Uuid::randomHex());

        $this->documentGenerator->preview(InvoiceRenderer::TYPE, $operation, '', $this->context);
    }

    public function testPreviewInvoice(): void
    {
        $order = $this->getContainer()->get('order.repository')->search(new Criteria([$this->orderId])$this->context)->first();
        

        $token = $this->getLoggedInContextToken($isGuest ? $this->guestId : $this->customerId, $this->ids->get('sales-channel'));

        $this->browser->setServerParameter('HTTP_SW_CONTEXT_TOKEN', $token);

        $operation = new DocumentGenerateOperation($this->ids->get('order'));
        $document = $this->documentGenerator->generate(InvoiceRenderer::TYPE, [$operation->getOrderId() => $operation], Context::createDefaultContext())->getSuccess()->first();
        static::assertInstanceOf(DocumentIdStruct::class$document);
        $deepLinkCode = '';

        if ($withValidDeepLinkCode !== null) {
            $deepLinkCode = $withValidDeepLinkCode ? $document->getDeepLinkCode() : Uuid::randomHex();
        }

        $endpoint = \sprintf('/store-api/document/download/%s', $document->getId());

        if ($deepLinkCode !== '') {
            $endpoint .= '/' . $deepLinkCode;
        }

        $this->browser
            ->request(
                'GET',
                
Home | Imprint | This part of the site doesn't use cookies.