FoundCombination example

$this->findVariantRouteMock->method('load')->with(
            $ids->get('product'),
            new Request(
                [
                    'options' => $options,
                    'switchedGroup' => $ids->get('element'),
                ]
            )
        )
            ->willReturn(
                new FindProductVariantRouteResponse(new FoundCombination($ids->get('variantId')$options))
            );

        $this->seoUrlPlaceholderHandlerMock->method('generate')->with(
            'frontend.detail.page',
            ['productId' => $ids->get('variantId')]
        )->willReturn('https://test.com/test');

        $this->seoUrlPlaceholderHandlerMock->method('replace')->willReturnArgument(0);

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

        
    public function load(string $productId, Request $request, SalesChannelContext $context): FindProductVariantRouteResponse
    {
        /** @var string|null $switchedGroup */
        $switchedGroup = $request->get('switchedGroup');

        /** @var array<string, string> $options */
        $options = $request->get('options') ? $request->get('options', []) : [];

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

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

        while (\count($options) > 1) {
            foreach ($options as $groupId => $_optionId) {
                if ($groupId !== $switchedGroup) {
                    unset($options[$groupId]);

                    break;
                }
            }

            

    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'),
        ];

        $foundCombo = new FoundCombination($ids->get('variantId')$options);

        static::assertEquals($ids->get('variantId')$foundCombo->getVariantId());
        static::assertEquals($options$foundCombo->getOptions());
    }
}
use Shopware\Core\Framework\Uuid\Uuid;

/** * @internal * * @covers \Shopware\Core\Content\Product\SalesChannel\FindVariant\FindProductVariantRouteResponse */
class FindProductVariantRouteResponseTest extends TestCase
{
    public function testInstantiate(): void
    {
        $response = new FindProductVariantRouteResponse(new FoundCombination(Uuid::randomHex()[]));

        static::assertInstanceOf(FoundCombination::class$response->getFoundCombination());
    }
}
Home | Imprint | This part of the site doesn't use cookies.