enableInheritance example


                'id' => $variantId = Uuid::randomHex(),
                'productNumber' => 'SW10001.1',
                'parentId' => $productId,
                'stock' => 1,
            ],
        ]$context);

        $product = $this->productRepository->search(new Criteria([$productId])$context)->getEntities()->first();
        static::assertNotNull($product);

        $variant = $context->enableInheritance(fn (Context $context): ?ProductEntity => $this->productRepository->search(new Criteria([$variantId])$context)->getEntities()->first());
        static::assertNotNull($variant);

        static::assertTrue($product->hasExtension('oneToOneInherited'));
        $productExtension = $product->getExtension('oneToOneInherited');
        static::assertInstanceOf(ArrayEntity::class$productExtension);
        $actualProductDate = $productExtension->get('myDate');
        static::assertInstanceOf(\DateTimeImmutable::class$actualProductDate);
        static::assertSame($myDate$actualProductDate->format(Defaults::STORAGE_DATE_TIME_FORMAT));

        // This should be true         static::assertTrue($variant->hasExtension('oneToOneInherited'));
        
$filteredTagIdsStruct->getIds()
        );
    }

    public function testFilterIdsWithAggregatedSortingWithInheritedAndVersionized(): void
    {
        $versionContext = $this->prepareTestDataWithInheritedAndVersionized();

        $criteria = new Criteria();
        $criteria->addSorting(new CountSorting('products.id', FieldSorting::DESCENDING));

        Context::createDefaultContext()->enableInheritance(function DContext $context) use ($criteria): void {
            $filteredTagIdsStruct = $this->filterTagIdsService->filterIds(
                new Request(),
                $criteria,
                $context
            );

            static::assertEquals(2, $filteredTagIdsStruct->getTotal());
            static::assertEquals(
                [
                    $this->ids->get('g'),
                    $this->ids->get('f'),
                ],
$config = $route->getConfig();

        $repository = $this->definitionRegistry->getRepository($config->getDefinition()->getEntityName());

        $associations = $this->getAssociations($template$repository->getDefinition());
        $criteria->addAssociations($associations);

        $criteria->setLimit(50);

        /** @var RepositoryIterator<LandingPageCollection|CategoryCollection|ProductCollection> $iterator */
        $iterator = $context->enableInheritance(static fn (Context $context): RepositoryIterator => new RepositoryIterator($repository$context$criteria));

        $this->setTwigTemplate($config$template);

        while ($entities = $iterator->fetch()) {
            yield from $this->generateUrls($route$config$salesChannel$entities);
        }
    }

    /** * @param EntityCollection<Entity> $entities * * @return iterable<SeoUrlEntity> */

    public function testOneToManyInherited(IdsCollection $ids): void
    {
        $criteria = new Criteria($ids->prefixed('product-'));
        $criteria->addFilter(
            new AndFilter([
                new EqualsFilter('product.prices.ruleId', $ids->get('rule-1')),
                new RangeFilter('product.prices.price', [RangeFilter::GTE => 100]),
            ])
        );

        $result = Context::createDefaultContext()->enableInheritance(fn (Context $context) => $this->getContainer()->get('product.repository')
            ->searchIds($criteria$context));

        static::assertEquals(3, $result->getTotal());
        static::assertTrue($result->has($ids->get('product-2')));
        static::assertTrue($result->has($ids->get('product-1')));
        static::assertTrue($result->has($ids->get('product-1-variant')));
    }

    /** * @depends testIndexing */
    
Home | Imprint | This part of the site doesn't use cookies.