createDocumentWithFile example


        $context = Context::createDefaultContext();

        $customerId = $this->createCustomer($context);
        $orderId = $this->createOrder($customerId$context);

        $criteria = new Criteria([$orderId]);
        $criteria->addAssociation('orderCustomer');
        $order = $this->getContainer()->get('order.repository')->search($criteria$context)->get($orderId);
        static::assertInstanceOf(OrderEntity::class$order);

        $documentId = $this->createDocumentWithFile($orderId$context);
        $documentIds = [$documentId];

        $criteria = new Criteria();
        $criteria->setLimit(1);
        /** @var ?MailTemplateEntity $mailTemplate */
        $mailTemplate = $this->getContainer()
            ->get('mail_template.repository')
            ->search($criteria$context)
            ->first();
        static::assertInstanceOf(MailTemplateEntity::class$mailTemplate);

        
$criteria = new Criteria([$orderId]);
        $criteria->addAssociation('transactions.stateMachineState');
        /** @var OrderEntity $order */
        $order = $orderRepository->search($criteria$context)->first();
        $event = new CheckoutOrderPlacedEvent($context$order, TestDefaults::SALES_CHANNEL);

        $documentIdOlder = null;
        $documentIdNewer = null;
        $documentIds = [];

        if ($documentTypeIds !== null && $documentTypeIds !== [] || $hasOrderSettingAttachment) {
            $documentIdOlder = $this->createDocumentWithFile($orderId$context);
            $documentIdNewer = $this->createDocumentWithFile($orderId$context);
            $documentIds[] = $documentIdNewer;
        }

        if ($hasOrderSettingAttachment) {
            $event->getContext()->addExtension(
                MailSendSubscriberConfig::MAIL_CONFIG_EXTENSION,
                new MailSendSubscriberConfig(
                    false,
                    $documentIds,
                )
            );
static::assertEquals($invoice->getId()$storno->getReferencedDocumentId());
        static::assertSame($storno->getOrderVersionId()$invoice->getOrderVersionId());
    }

    /** * @group slow */
    public function testCreateFileIsWrittenInFs(): void
    {
        /** @var FilesystemOperator $fileSystem */
        $fileSystem = $this->getContainer()->get('shopware.filesystem.private');
        $document = $this->createDocumentWithFile();

        /** @var UrlGenerator $urlGenerator */
        $urlGenerator = $this->getContainer()->get(UrlGeneratorInterface::class);

        static::assertNotNull($document->getDocumentMediaFile());
        $filePath = $urlGenerator->getRelativeMediaUrl($document->getDocumentMediaFile());

        static::assertTrue($fileSystem->has($filePath));
        $fileSystem->delete($filePath);
        static::assertFalse($fileSystem->has($filePath));
    }

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