getDisplayParent example


    public function testDecode(): void
    {
        $json = '{"displayParent": true, "mainVariantId": "123", "configuratorGroupConfig": null}';

        $field = new VariantListingConfigField('test', 'test');

        $decoded = $this->serializer->decode($field$json);

        static::assertInstanceOf(VariantListingConfig::class$decoded);
        static::assertTrue($decoded->getDisplayParent());
        static::assertSame('123', $decoded->getMainVariantId());
        static::assertNull($decoded->getConfiguratorGroupConfig());
    }

    /** * @throws \JsonException */
    public function testDecodeNullValue(): void
    {
        $field = new VariantListingConfigField('test', 'test');

        

class VariantListingConfigTest extends TestCase
{
    public function testInstantiate(): void
    {
        $displayParent = true;
        $mainVariantId = '1';
        $configuratorGroupConfig = ['key' => 'value'];

        $variantListingConfig = new VariantListingConfig($displayParent$mainVariantId$configuratorGroupConfig);

        static::assertSame($displayParent$variantListingConfig->getDisplayParent());
        static::assertSame($mainVariantId$variantListingConfig->getMainVariantId());
        static::assertSame($configuratorGroupConfig$variantListingConfig->getConfiguratorGroupConfig());
    }
}

    private function checkVariantListingConfig(string $productId, SalesChannelContext $context): ?string
    {
        /** @var SalesChannelProductEntity|null $product */
        $product = $this->productRepository->search(new Criteria([$productId])$context)->first();

        if ($product === null || $product->getParentId() !== null) {
            return null;
        }

        if (($listingConfig = $product->getVariantListingConfig()) === null || $listingConfig->getDisplayParent() !== true) {
            return null;
        }

        return $listingConfig->getMainVariantId();
    }

    /** * @throws InconsistentCriteriaIdsException */
    private function findBestVariant(string $productId, SalesChannelContext $context): string
    {
        
'id' => Uuid::fromHexToBytes($ids->get('product-1')),
        ]);

        /** @var EntityRepository $productRepository */
        $productRepository = self::getContainer()->get('product.repository');
        /** @var ProductEntity $product */
        $product = $productRepository->search(new Criteria([$ids->get('product-1')]), Context::createDefaultContext())->first();
        static::assertNotNull($product);

        $config = $product->getVariantListingConfig();
        static::assertNotNull($config);
        static::assertFalse($config->getDisplayParent());
        static::assertEquals($ids->get('variant-1-2')$config->getMainVariantId());
        static::assertEquals([]$config->getConfiguratorGroupConfig());

        $this->migration->update($this->connection);

        /** @var ProductEntity $product */
        $product = $productRepository->search(new Criteria([$ids->get('product-1')]), Context::createDefaultContext())->first();
        static::assertNotNull($product);

        $config = $product->getVariantListingConfig();
        static::assertNotNull($config);
        
Home | Imprint | This part of the site doesn't use cookies.