getDocumentIds example

#[Route(path: '/api/_action/order/{orderId}/state/{transition}', name: 'api.action.order.state_machine.order.transition_state', methods: ['POST'])]     public function orderStateTransition(
        string $orderId,
        string $transition,
        Request $request,
        Context $context
    ): JsonResponse {
        $documentTypes = $request->request->all('documentTypes');
        if (\count($documentTypes) > 0) {
            $skipSentDocuments = (bool) $request->request->get('skipSentDocuments', false);
            $documentIds = $this->getDocumentIds('order', $orderId$documentTypes$skipSentDocuments);
        } else {
            $documentIds = $request->request->all('documentIds');
        }

        $mediaIds = $request->request->all('mediaIds');

        $context->addExtension(
            MailSendSubscriberConfig::MAIL_CONFIG_EXTENSION,
            new MailSendSubscriberConfig(
                $request->request->get('sendMail', true) === false,
                $documentIds,
                
foreach ($mailTemplate->getMedia() ?? [] as $mailTemplateMedia) {
            if ($mailTemplateMedia->getMedia() === null || $mailTemplateMedia->getLanguageId() !== $context->getLanguageId()) {
                continue;
            }

            $attachments[] = $this->mediaService->getAttachment(
                $mailTemplateMedia->getMedia(),
                $context
            );
        }

        $documentIds = $extensions->getDocumentIds();

        if (!empty($eventConfig['documentTypeIds']) && \is_array($eventConfig['documentTypeIds']) && $orderId) {
            $latestDocuments = $this->getLatestDocumentsOfTypes($orderId$eventConfig['documentTypeIds']);

            $documentIds = array_unique(array_merge($documentIds$latestDocuments));
        }

        if (!empty($documentIds)) {
            $extensions->setDocumentIds($documentIds);
            $attachments = $this->mappingAttachments($documentIds$attachments$context);
        }

        
$this->setDocumentsSent($attachments$config->getExtension()$config->getContext());

        return $sentMessage;
    }

    /** * @param array<int, array{id?: string, content: string, fileName: string, mimeType: string|null}> $attachments */
    private function setDocumentsSent(array $attachments, MailSendSubscriberConfig $extension, Context $context): void
    {
        $documentAttachments = array_filter($attachmentsfn (array $attachment) => \in_array($attachment['id'] ?? null, $extension->getDocumentIds(), true));

        $documentAttachments = array_column($documentAttachments, 'id');

        if (empty($documentAttachments)) {
            return;
        }

        $payload = array_map(static fn (string $documentId) => [
            'id' => $documentId,
            'sent' => true,
        ]$documentAttachments);

        

                json_encode($payload) ?: ''
            );

            $response = $this->getBrowser()->getResponse();
            static::assertEquals(200, $response->getStatusCode());
            $response = json_decode($response->getContent() ?: '', true, 512, \JSON_THROW_ON_ERROR);
            static::assertNotEmpty($response);
            static::assertNotEmpty($data = $response['data']);
            static::assertCount(2, $data);

            $documentIds = [...$documentIds, ...$this->getDocumentIds($data)];
        }

        $documents = $this->getDocumentByDocumentIds($documentIds);

        static::assertNotEmpty($documents);
        static::assertCount(8, $documents);
    }

    public function testCreateDocumentWithInvalidDocumentTypeName(): void
    {
        $order = $this->createOrder($this->customerId, $this->context);
        

                (string) json_encode($payload)
            );

            $response = $this->getBrowser()->getResponse();
            static::assertEquals(200, $response->getStatusCode());
            $response = json_decode((string) $response->getContent(), true, 512, \JSON_THROW_ON_ERROR);
            static::assertArrayHasKey('data', $response);
            static::assertNotEmpty($data = $response['data']);
            static::assertCount(2, $data);

            $documentIds = array_merge($documentIds$this->getDocumentIds($data));
        }

        $documents = $this->getDocumentByDocumentIds($documentIds);

        static::assertNotEmpty($documents);
        static::assertCount(8, $documents);
    }

    public function testCreateDocumentWithInvalidDocumentTypeName(): void
    {
        static::assertNotNull($customer = $this->salesChannelContext->getCustomer());
        
Home | Imprint | This part of the site doesn't use cookies.