SalesChannelNotFoundException example

protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $productExportId = $input->getArgument('product-export-id');
        $salesChannelId = $input->getArgument('sales-channel-id');
        $forceGeneration = $input->getOption('force');
        $includeInactive = $input->getOption('include-inactive');

        $salesChannelContext = $this->salesChannelContextFactory->create(Uuid::randomHex()$salesChannelId);

        if ($salesChannelContext->getSalesChannel()->getTypeId() !== Defaults::SALES_CHANNEL_TYPE_STOREFRONT) {
            throw new SalesChannelNotFoundException();
        }

        $this->productExportService->export(
            $salesChannelContext,
            new ExportBehavior($forceGeneration$includeInactive),
            $productExportId
        );

        return self::SUCCESS;
    }
}
$recipients = $data['recipients'];
        $salesChannelId = $data['salesChannelId'];
        $salesChannel = null;

        if (($salesChannelId !== null && !isset($templateData['salesChannel'])) || $this->isTestMode($data)) {
            $criteria = $this->getSalesChannelDomainCriteria($salesChannelId$context);

            /** @var SalesChannelEntity|null $salesChannel */
            $salesChannel = $this->salesChannelRepository->search($criteria$context)->get($salesChannelId);

            if ($salesChannel === null) {
                throw new SalesChannelNotFoundException($salesChannelId);
            }

            $templateData['salesChannel'] = $salesChannel;
        } elseif ($this->templateDataContainsSalesChannel($templateData)) {
            $salesChannel = $templateData['salesChannel'];
        }

        $senderEmail = $data['senderMail'] ?? $this->getSender($data$salesChannelId);

        if ($senderEmail === null) {
            $event = new MailErrorEvent(
                
$this->finalizeExport($productExport$filePath);
    }

    private function getContext(ProductExportPartialGeneration $productExportPartialGeneration): Context
    {
        $context = $this->salesChannelContextFactory->create(
            Uuid::randomHex(),
            $productExportPartialGeneration->getSalesChannelId()
        );

        if ($context->getSalesChannel()->getTypeId() !== Defaults::SALES_CHANNEL_TYPE_STOREFRONT) {
            throw new SalesChannelNotFoundException();
        }

        return $context->getContext();
    }

    private function fetchProductExport(
        ProductExportPartialGeneration $productExportPartialGeneration,
        Context $context
    ): ?ProductExportEntity {
        $criteria = new Criteria([$productExportPartialGeneration->getProductExportId()]);
        $criteria
            
$this->salesChannelRepository,
            $this->createMock(SystemConfigService::class),
            $this->eventDispatcher,
            $this->createMock(UrlGeneratorInterface::class),
            $this->logger,
        );
    }

    public function testThrowSalesChannelNotFound(): void
    {
        $salesChannelId = Uuid::randomHex();
        $exception = new SalesChannelNotFoundException($salesChannelId);
        static::expectExceptionObject($exception);

        $data = [
            'recipients' => [],
            'salesChannelId' => $salesChannelId,
        ];

        $this->mailService->send($data, Context::createDefaultContext());
    }

    public function testSendMailSuccess(): void
    {

        return new InvalidSalesChannelIdException($salesChannelId);
    }

    public static function invalidVersionName(): ShopwareHttpException
    {
        return new InvalidVersionNameException();
    }

    public static function salesChannelNotFound(): ShopwareHttpException
    {
        return new SalesChannelNotFoundException();
    }

    public static function deleteLiveVersion(): ShopwareHttpException
    {
        return new LiveVersionDeleteException();
    }

    /** * @param array<mixed> $payload */
    public static function resourceNotFound(string $entity, array $payload): ShopwareHttpException
    {
private function getSalesChannel(string $salesChannelId, Context $context): SalesChannelEntity
    {
        $criteria = new Criteria([$salesChannelId]);

        $salesChannel = $this->salesChannelRepository->search(
            $criteria,
            $context
        )->get($salesChannelId);

        if (!($salesChannel instanceof SalesChannelEntity)) {
            $salesChannelNotFoundException = new SalesChannelNotFoundException($salesChannelId);
            $loggingEvent = new ProductExportLoggingEvent(
                $context,
                $salesChannelNotFoundException->getMessage(),
                Level::Error,
                $salesChannelNotFoundException
            );
            $this->eventDispatcher->dispatch($loggingEvent);

            throw $salesChannelNotFoundException;
        }

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