getSalesChannelDomain example

        $messagesBefore = $bus->getDispatchedMessages();
        $this->getTaskHandler()->run();
        $messagesAfter = $bus->getDispatchedMessages();

        static::assertCount(\count($messagesBefore)$messagesAfter);
    }

    protected function createSecondStorefrontSalesChannel(): void
    {
        $salesChannelRepository = $this->getContainer()->get('sales_channel.repository');
        $criteria = (new Criteria())
            ->setIds([$this->getSalesChannelDomain()->getSalesChannelId()])
            ->addAssociation('languages');

        /** @var SalesChannelEntity $originalSalesChannel */
        $originalSalesChannel = $salesChannelRepository->search($criteria$this->context)->first();

        /** @var LanguageCollection $originalSalesChannelLanguages */
        $originalSalesChannelLanguages = $originalSalesChannel->getLanguages();
        $originalSalesChannelArray = $originalSalesChannelLanguages->jsonSerialize();
        $languages = array_map(static fn ($language) => ['id' => $language->getId()]$originalSalesChannelArray);

        $id = '000000009276457086da48d5b5628f3c';
        

        $this->context = Context::createDefaultContext();
    }

    public function testValidate(): void
    {
        $this->createProductStream();

        $url = '/api/_action/product-export/validate';

        $content = json_encode([
            'salesChannelId' => $this->getSalesChannelDomain()->getSalesChannelId(),
            'salesChannelDomainId' => $this->getSalesChannelDomainId(),
            'productStreamId' => '137b079935714281ba80b40f83f8d7eb',
            'headerTemplate' => '',
            'bodyTemplate' => '{{ product.name }}',
            'footerTemplate' => '',
            'includeVariants' => false,
            'encoding' => 'UTF-8',
            'fileFormat' => 'CSV',
            'fileName' => 'test.csv',
            'accessKey' => 'test',
            'currencyId' => Defaults::CURRENCY,
        ],
$contextToken,
            [
                SalesChannelContextService::CURRENCY_ID => $productExport->getCurrencyId(),
            ],
            $productExport->getSalesChannelId()
        );

        $context = $this->salesChannelContextService->get(
            new SalesChannelContextServiceParameters(
                $productExport->getStorefrontSalesChannelId(),
                $contextToken,
                $productExport->getSalesChannelDomain()->getLanguageId(),
                $productExport->getCurrencyId()
            )
        );

        $this->translator->injectSettings(
            $productExport->getStorefrontSalesChannelId(),
            $productExport->getSalesChannelDomain()->getLanguageId(),
            $this->languageLocaleProvider->getLocaleForLanguageId($productExport->getSalesChannelDomain()->getLanguageId()),
            $context->getContext()
        );

        
/** @var ProductExportEntity|null $productExport */
        $productExport = $this->productExportRepository->search($criteria, Context::createDefaultContext())->first();

        if ($productExport === null) {
            $exportNotFoundException = new ExportNotFoundException(null, $request->get('fileName'));
            $this->logException(Context::createDefaultContext()$exportNotFoundException, Level::Warning);

            throw $exportNotFoundException;
        }

        $context = $this->contextFactory->create('', $productExport->getSalesChannelDomain()->getSalesChannelId());

        $filePath = $this->productExportFileHandler->getFilePath($productExport);

        // if file not present or interval = live         if (!$this->fileSystem->fileExists($filePath) || $productExport->getInterval() === 0) {
            $this->productExportService->export($contextnew ExportBehavior()$productExport->getId());
        }

        if (!$this->fileSystem->fileExists($filePath)) {
            $exportNotGeneratedException = new ExportNotGeneratedException();
            $this->logException($context->getContext()$exportNotGeneratedException);

            
'salesChannelId' => $this->getSalesChannelId(),
                'salesChannelDomainId' => $this->getSalesChannelDomainId(),
                'generateByCronjob' => false,
                'currencyId' => Defaults::CURRENCY,
            ],
        ]$this->context);

        $criteria = new Criteria([$id]);
        $criteria->addAssociation('salesChannelDomain');
        $entity = $this->repository->search($criteria$this->context)->get($id);

        static::assertNotNull($entity->getSalesChannelDomain());
    }

    protected function getSalesChannelId(): string
    {
        /** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('sales_channel.repository');

        return $repository->search(new Criteria()$this->context)->first()->getId();
    }

    protected function getSalesChannelDomainId(): string
    {
private function getSalesChannelDomain(): SalesChannelDomainEntity
    {
        /** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('sales_channel_domain.repository');

        return $repository->search(new Criteria()$this->context)->first();
    }

    private function getSalesChannelDomainId(): string
    {
        return $this->getSalesChannelDomain()->getId();
    }

    private function createTestEntity(array $override = []): string
    {
        $this->createProductStream();

        $id = Uuid::randomHex();
        $this->repository->upsert([
            array_merge([
                'id' => $id,
                'fileName' => 'Testexport.csv',
                
$contextToken,
            [
                SalesChannelContextService::CURRENCY_ID => $productExport->getCurrencyId(),
            ],
            $productExport->getSalesChannelId()
        );

        $context = $this->salesChannelContextService->get(
            new SalesChannelContextServiceParameters(
                $productExport->getStorefrontSalesChannelId(),
                $contextToken,
                $productExport->getSalesChannelDomain()->getLanguageId(),
                $productExport->getSalesChannelDomain()->getCurrencyId() ?? $productExport->getCurrencyId()
            )
        );

        $this->translator->injectSettings(
            $productExport->getStorefrontSalesChannelId(),
            $productExport->getSalesChannelDomain()->getLanguageId(),
            $this->languageLocaleProvider->getLocaleForLanguageId($productExport->getSalesChannelDomain()->getLanguageId()),
            $context->getContext()
        );

        
$entity->setFileName($dataBag->get('fileName'));
        $entity->setAccessKey($dataBag->get('accessKey'));
        $entity->setSalesChannelId($dataBag->get('salesChannelId'));
        $entity->setSalesChannelDomainId($dataBag->get('salesChannelDomainId'));
        $entity->setCurrencyId($dataBag->get('currencyId'));

        return $entity;
    }

    private function generateExportPreview(RequestDataBag $dataBag, Context $context): ?ProductExportResult
    {
        $salesChannelDomain = $this->getSalesChannelDomain($dataBag->get('salesChannelDomainId')$context);
        $salesChannel = $this->getSalesChannel($dataBag->get('salesChannelId')$context);

        $productExportEntity = $this->createEntity($dataBag);
        $productExportEntity->setSalesChannelDomain($salesChannelDomain);
        $productExportEntity->setStorefrontSalesChannelId($salesChannelDomain->getSalesChannelId());
        $productExportEntity->setSalesChannel($salesChannel);

        $exportBehavior = new ExportBehavior(true, true, true);

        return $this->productExportGenerator->generate($productExportEntity$exportBehavior);
    }

    
private FilesystemOperator $fileSystem;

    protected function setUp(): void
    {
        $this->repository = $this->getContainer()->get('product_export.repository');
        $this->service = $this->getContainer()->get(ProductExporter::class);
        $this->context = Context::createDefaultContext();
        $this->fileSystem = $this->getContainer()->get('shopware.filesystem.private');

        $salesChannelContextFactory = $this->getContainer()->get(SalesChannelContextFactory::class);
        $this->salesChannelContext = $salesChannelContextFactory->create(Uuid::randomHex()$this->getSalesChannelDomain()->getSalesChannelId());
    }

    public function testExport(): void
    {
        $this->createTestEntity();

        $this->service->export($this->salesChannelContext, new ExportBehavior());

        $filePath = sprintf('%s/Testexport.csv', $this->getContainer()->getParameter('product_export.directory'));
        $fileContent = $this->fileSystem->read($filePath);

        
$this->eventDispatcher->dispatch($loggingEvent);
    }

    private function replaceSeoUrlPlaceholder(
        string $content,
        ProductExportEntity $productExportEntity,
        SalesChannelContext $salesChannelContext
    ): string {
        return $this->seoUrlPlaceholderHandler->replace(
            $content,
            $productExportEntity->getSalesChannelDomain()->getUrl(),
            $salesChannelContext
        );
    }
}

        if (!$this->getContainer()->has(ProductPageSeoUrlRoute::class)) {
            static::markTestSkipped('ProductExport tests need storefront bundle to be active');
        }

        $this->repository = $this->getContainer()->get('product_export.repository');
        $this->context = Context::createDefaultContext();
        $this->fileSystem = $this->getContainer()->get('shopware.filesystem.private');
        $this->productExportGenerateCommand = $this->getContainer()->get(ProductExportGenerateCommand::class);

        $salesChannelContextFactory = $this->getContainer()->get(SalesChannelContextFactory::class);
        $this->salesChannelContext = $salesChannelContextFactory->create(Uuid::randomHex()$this->getSalesChannelDomain()->getSalesChannelId());
    }

    public function testExecute(): void
    {
        $this->createTestEntity();

        $input = new StringInput($this->getSalesChannelDomain()->getSalesChannelId());
        $output = new BufferedOutput();

        $this->runCommand($this->productExportGenerateCommand, $input$output);

        

    private $service;

    protected function setUp(): void
    {
        $this->repository = $this->getContainer()->get('product_export.repository');
        $this->service = $this->getContainer()->get(ProductExportGenerator::class);
        $this->context = Context::createDefaultContext();

        $salesChannelContextFactory = $this->getContainer()->get(SalesChannelContextFactory::class);
        $this->salesChannelContext = $salesChannelContextFactory->create(Uuid::randomHex()$this->getSalesChannelDomain()->getSalesChannelId());
    }

    public function testValidXmlExport(): void
    {
        $productExportId = $this->createTestEntity();

        $criteria = new Criteria([$productExportId]);
        $criteria->addAssociation('salesChannelDomain.language');
        $criteria->addAssociation('salesChannel');

        /** @var ProductExportEntity $productExport */
        
Home | Imprint | This part of the site doesn't use cookies.