salesChannelNotFound example



    public function testInvalidVersionName(): void
    {
        $exception = ApiException::invalidVersionName();

        static::assertInstanceOf(InvalidVersionNameException::class$exception);
    }

    public function testSalesChannelNotFound(): void
    {
        $exception = ApiException::salesChannelNotFound();

        static::assertInstanceOf(SalesChannelNotFoundException::class$exception);
    }

    public function testDeleteLiveVersion(): void
    {
        $exception = ApiException::deleteLiveVersion();

        static::assertInstanceOf(LiveVersionDeleteException::class$exception);
    }

    
$this->userRecoveryRepo->delete([$recoveryData]$context);
    }

    /** * pick a random sales channel to form sales channel context as flow builder requires it */
    private function getSalesChannel(Context $context): SalesChannelEntity
    {
        $salesChannel = $this->salesChannelRepository->search((new Criteria())->setLimit(1)$context)->first();

        if (!$salesChannel instanceof SalesChannelEntity) {
            throw UserException::salesChannelNotFound();
        }

        return $salesChannel;
    }
}
$accessKey = $request->headers->get(PlatformRequest::HEADER_ACCESS_KEY);
        if (!$accessKey) {
            throw ApiException::unauthorized(
                'header',
                sprintf('Header "%s" is required.', PlatformRequest::HEADER_ACCESS_KEY)
            );
        }

        $origin = AccessKeyHelper::getOrigin($accessKey);
        if ($origin !== 'sales-channel') {
            throw ApiException::salesChannelNotFound();
        }

        $salesChannelData = $this->getSalesChannelData($accessKey);

        $this->handleMaintenanceMode($request$salesChannelData);

        $request->attributes->set(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID, $salesChannelData['id']);
    }

    protected function getScopeRegistry(): RouteScopeRegistry
    {
        
$salesChannelId = $seoUrlData['salesChannelId'] ?? null;

        if ($salesChannelId === null) {
            throw SeoException::salesChannelIdParameterIsMissing();
        }

        /** @var SalesChannelEntity|null $salesChannel */
        $salesChannel = $this->salesChannelRepository->search(new Criteria([$salesChannelId])$context)->first();

        if ($salesChannel === null) {
            throw SeoException::salesChannelNotFound($salesChannelId);
        }

        if ($salesChannel->getTypeId() === Defaults::SALES_CHANNEL_TYPE_API) {
            if (Feature::isActive('v6.6.0.0')) {
                return new Response('', Response::HTTP_NO_CONTENT);
            }
        }

        $this->seoUrlPersister->updateSeoUrls(
            $context,
            $seoUrlData['routeName'],
            [
static::assertEquals($statusCode$caughtException->getStatusCode());
        static::assertEquals($errorCode$caughtException->getErrorCode());
        static::assertEquals($message$caughtException->getMessage());
    }

    /** * @return array<string, array{exception: ShopwareHttpException|CountryException, statusCode: int, errorCode: string, message: string}> */
    public static function exceptionDataProvider(): iterable
    {
        yield UserException::SALES_CHANNEL_NOT_FOUND => [
            'exception' => UserException::salesChannelNotFound(),
            'statusCode' => Response::HTTP_PRECONDITION_FAILED,
            'errorCode' => UserException::SALES_CHANNEL_NOT_FOUND,
            'message' => 'No sales channel found.',
        ];
    }
}

        $context = $this->getContext($salesChannelId$options);

        $criteria = new Criteria([$salesChannelId]);
        $criteria->setTitle('base-context-factory::sales-channel');
        $criteria->addAssociation('currency');
        $criteria->addAssociation('domains');

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

        if (!$salesChannel instanceof SalesChannelEntity) {
            throw SalesChannelException::salesChannelNotFound($salesChannelId);
        }

        // load active currency, fallback to shop currency         /** @var CurrencyEntity $currency */
        $currency = $salesChannel->getCurrency();

        if (\array_key_exists(SalesChannelContextService::CURRENCY_ID, $options)) {
            $currencyId = $options[SalesChannelContextService::CURRENCY_ID];
            \assert(\is_string($currencyId) && Uuid::isValid($currencyId));

            $criteria = new Criteria([$currencyId]);
            
private const MAINTENANCE_ALLOWED_IPS = ['192.168.0.2', '192.168.0.1', '192.168.0.3'];

    public function testInactiveSalesChannel(): void
    {
        $browser = $this->createSalesChannelBrowser(salesChannelOverrides: ['active' => false]);
        $browser->request(Request::METHOD_GET, '/store-api/test/sales-channel-authentication-listener/default');

        $this->assertExceptionResponse(
            $browser,
            Response::HTTP_PRECONDITION_FAILED,
            ApiException::salesChannelNotFound()->getErrorCode()
        );
    }

    public function testActiveSalesChannel(): void
    {
        $browser = $this->createSalesChannelBrowser(salesChannelOverrides: ['active' => true]);
        $browser->request(Request::METHOD_GET, '/store-api/test/sales-channel-authentication-listener/default');

        $this->assertResponseSuccess($browser);
    }

    

    public static function exceptionDataProvider(): iterable
    {
        yield SalesChannelException::SALES_CHANNEL_LANGUAGE_NOT_AVAILABLE_EXCEPTION => [
            'exception' => SalesChannelException::providedLanguageNotAvailable('myCustomScn', ['scn1', 'scn2']),
            'statusCode' => Response::HTTP_PRECONDITION_FAILED,
            'errorCode' => SalesChannelException::SALES_CHANNEL_LANGUAGE_NOT_AVAILABLE_EXCEPTION,
            'message' => 'Provided language "myCustomScn" is not in list of available languages: scn1, scn2',
        ];

        yield SalesChannelException::SALES_CHANNEL_DOES_NOT_EXISTS_EXCEPTION => [
            'exception' => SalesChannelException::salesChannelNotFound('myCustomScn'),
            'statusCode' => Response::HTTP_NOT_FOUND,
            'errorCode' => SalesChannelException::SALES_CHANNEL_DOES_NOT_EXISTS_EXCEPTION,
            'message' => 'Sales channel with id "myCustomScn" not found or not valid!.',
        ];

        yield SalesChannelException::LANGUAGE_INVALID_EXCEPTION => [
            'exception' => SalesChannelException::invalidLanguageId(),
            'statusCode' => Response::HTTP_PRECONDITION_FAILED,
            'errorCode' => SalesChannelException::LANGUAGE_INVALID_EXCEPTION,
            'message' => 'Provided languageId is not a valid uuid',
        ];

        
$exception = SeoException::routeNameParameterIsMissing();

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        static::assertEquals(SeoException::ROUTE_NAME_PARAMETER_IS_MISSING, $exception->getErrorCode());
        static::assertEquals('Parameter "routeName" is missing.', $exception->getMessage());
    }

    public function testSalesChannelNotFound(): void
    {
        $salesChannelId = 'not-found-sales-channel-id';

        $exception = SeoException::salesChannelNotFound($salesChannelId);

        static::assertEquals(Response::HTTP_NOT_FOUND, $exception->getStatusCode());
        static::assertEquals(SeoException::SALES_CHANNEL_NOT_FOUND, $exception->getErrorCode());
        static::assertEquals('Sales channel with id "not-found-sales-channel-id" not found.', $exception->getMessage());
        static::assertEquals(['salesChannelId' => $salesChannelId]$exception->getParameters());
    }
}
Home | Imprint | This part of the site doesn't use cookies.