invalidSalesChannelId example

/** * @throws InconsistentCriteriaIdsException * @throws InvalidSalesChannelIdException */
    private function fetchSalesChannel(string $salesChannelId, Context $context): SalesChannelEntity
    {
        /** @var SalesChannelEntity|null $salesChannel */
        $salesChannel = $this->salesChannelRepository->search(new Criteria([$salesChannelId])$context)->get($salesChannelId);

        if ($salesChannel === null) {
            throw ApiException::invalidSalesChannelId($salesChannelId);
        }

        return $salesChannel;
    }

    private function getContextToken(Request $request): string
    {
        $contextToken = $request->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN);

        if ($contextToken === null) {
            $contextToken = Random::getAlphanumericString(32);
        }
throw SeoException::noEntitiesForPreview($repository->getDefinition()->getEntityName()$seoUrlTemplate['routeName']);
        }

        $salesChannelId = $seoUrlTemplate['salesChannelId'] ?? null;
        $template = $seoUrlTemplate['template'] ?? '';

        if (\is_string($salesChannelId)) {
            /** @var SalesChannelEntity|null $salesChannel */
            $salesChannel = $this->salesChannelRepository->search((new Criteria([$salesChannelId]))->setLimit(1)$context)->get($salesChannelId);

            if ($salesChannel === null) {
                throw SeoException::invalidSalesChannelId($salesChannelId);
            }
        } else {
            /** @var SalesChannelEntity|null $salesChannel */
            $salesChannel = $this->salesChannelRepository
                ->search(
                    (new Criteria())->addFilter(new EqualsFilter('typeId', Defaults::SALES_CHANNEL_TYPE_STOREFRONT))->setLimit(1),
                    $context
                )
                ->first();
        }

        

#[Package('buyers-experience')] class SeoExceptionTest extends TestCase
{
    public function testInvalidSalesChannelId(): void
    {
        $salesChannelId = 'invalid-sales-channel-id';

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

        static::assertInstanceOf(InvalidSalesChannelIdException::class$exception);
        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
    }

    public function testSalesChannelIdParameterIsMissing(): void
    {
        $exception = SeoException::salesChannelIdParameterIsMissing();

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        static::assertEquals(SeoException::SALES_CHANNEL_ID_PARAMETER_IS_MISSING, $exception->getErrorCode());
        
public function testInvalidSyncOperation(): void
    {
        $exception = ApiException::invalidSyncOperation('Message');

        static::assertInstanceOf(InvalidSyncOperationException::class$exception);
        static::assertEquals('Message', $exception->getMessage());
    }

    public function testInvalidSalesChannelId(): void
    {
        $exception = ApiException::invalidSalesChannelId('123');

        static::assertInstanceOf(InvalidSalesChannelIdException::class$exception);
        static::assertEquals('The provided salesChannelId "123" is invalid.', $exception->getMessage());
    }

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

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

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