VariantNotFoundException example


    public function testInstantiate(): void
    {
        $ids = new IdsCollection();

        $options = [
            $ids->get('groupId1') => $ids->get('optionId1'),
            $ids->get('groupId1') => $ids->get('optionId2'),
            $ids->get('groupId2') => $ids->get('optionId3'),
        ];

        $exception = new VariantNotFoundException($ids->get('productId')$options);

        static::assertEquals('CONTENT__PRODUCT_VARIANT_NOT_FOUND', $exception->getErrorCode());
        static::assertEquals(Response::HTTP_NOT_FOUND, $exception->getStatusCode());
        static::assertEquals(
            'Variant for productId ' . $ids->get('productId') . ' with options ' . \json_encode($options, \JSON_THROW_ON_ERROR) . ' not found.',
            $exception->getMessage()
        );
    }
}


    public function testSwitchVariantException(): void
    {
        $ids = new IdsCollection();

        $options = [
            $ids->get('group1') => $ids->get('option1'),
            $ids->get('group2') => $ids->get('option2'),
        ];

        $this->findVariantRouteMock->method('load')->willThrowException(new VariantNotFoundException($ids->get('product')$options));

        $response = $this->controller->switch($ids->get('product')new Request()$this->createMock(SalesChannelContext::class));

        static::assertEquals('{"url":"","productId":"' . $ids->get('product') . '"}', $response->getContent());
    }

    public function testQuickViewMinimal(): void
    {
        $ids = new IdsCollection();

        $request = new Request(['productId' => $ids->get('productId')]);
        
break;
                }
            }

            $variantId = $this->searchForOptions($productId$context$options);

            if ($variantId) {
                return new FindProductVariantRouteResponse(new FoundCombination($variantId$options));
            }
        }

        throw new VariantNotFoundException($productId$options);
    }

    /** * @param array<string, string> $options */
    private function searchForOptions(
        string $productId,
        SalesChannelContext $salesChannelContext,
        array $options
    ): ?string {
        $criteria = (new Criteria())
            
Home | Imprint | This part of the site doesn't use cookies.