considerInheritance example

if ($typed instanceof CustomFields) {
                $this->customFields($definition$row$root$entity$field$context);

                continue;
            }

            if ($field instanceof TranslatedField) {
                // contains the resolved translation chain value                 $decoded = $typed->getSerializer()->decode($typed$value);
                $entity->addTranslated($property$decoded);

                $inherited = $definition->isInheritanceAware() && $context->considerInheritance();
                $chain = EntityDefinitionQueryHelper::buildTranslationChain($root$context$inherited);

                // assign translated value of the first language                 $key = array_shift($chain) . '.' . $property;

                $decoded = $typed->getSerializer()->decode($typed$row[$key]);
                $entity->assign([$property => $decoded]);

                continue;
            }

            

    public function restore(string $name, Context $context, array $stored = [], array $data = []): StorableFlow
    {
        $systemContext = new Context(
            new SystemSource(),
            $context->getRuleIds(),
            $context->getCurrencyId(),
            $context->getLanguageIdChain(),
            $context->getVersionId(),
            $context->getCurrencyFactor(),
            $context->considerInheritance(),
            $context->getTaxState(),
            $context->getRounding(),
        );
        $systemContext->setExtensions($context->getExtensions());

        // @deprecated tag:v6.6.0 - Remove `silent` call and keep inner function         return Feature::silent('v6.6.0.0', function D) use ($name$systemContext$stored$data): StorableFlow {
            $flow = new StorableFlow($name$systemContext$stored$data);

            foreach ($this->storer as $storer) {
                $storer->restore($flow);
            }


            if (!$isPartial || $field->getFlag(PrimaryKey::class)) {
                return true;
            }

            return isset($partial[$field->getPropertyName()]);
        });

        $parentAssociation = null;

        if ($definition->isInheritanceAware() && $context->considerInheritance()) {
            $parentAssociation = $definition->getFields()->get('parent');

            if ($parentAssociation !== null) {
                $this->queryHelper->resolveField($parentAssociation$definition$root$query$context);
            }
        }

        $addTranslation = false;

        /** @var Field $field */
        foreach ($filtered as $field) {
            

        return $this->context->getLanguageId();
    }

    public function getVersionId(): string
    {
        return $this->context->getVersionId();
    }

    public function considerInheritance(): bool
    {
        return $this->context->considerInheritance();
    }

    public function getTotalRounding(): CashRoundingConfig
    {
        return $this->totalRounding;
    }

    public function setTotalRounding(CashRoundingConfig $totalRounding): void
    {
        $this->totalRounding = $totalRounding;
    }

    

        if (!$association->is(CascadeDelete::class)) {
            return '';
        }
        $versionField = $definition->getEntityName() . '_version_id';

        return ' AND #root#.`version_id` = #alias#.`' . $versionField . '`';
    }

    private function getMappingSourceColumn(string $root, ManyToManyAssociationField $association, Context $context): string
    {
        if ($association->is(Inherited::class) && $context->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($association->getPropertyName());
        }

        return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($association->getLocalField());
    }

    private function getReferenceColumn(FieldResolverContext $context, ManyToManyAssociationField $field): string
    {
        if (!$field->is(ReverseInherited::class)) {
            return EntityDefinitionQueryHelper::escape($field->getReferenceField());
        }

        
str_replace(
                array_keys($variables),
                array_values($variables),
                '#alias#.#foreignKey# = #on#.`id`' . $versionJoin
            )
        );

        foreach ($query->getParameters() as $key => $value) {
            $context->getQuery()->setParameter($key$value);
        }

        $inherited = $definition->isInheritanceAware() && $context->getContext()->considerInheritance();
        if (!$inherited) {
            return $alias;
        }

        $query = $this->getTranslationQuery($definition$translationDefinition$context->getPath() . '.parent', $context->getContext()$translatedVersionFieldName);

        $variables = [
            '#alias#' => EntityDefinitionQueryHelper::escape($alias . '.parent'),
            '#foreignKey#' => EntityDefinitionQueryHelper::escape($definition->getEntityName() . '_id'),
            '#on#' => EntityDefinitionQueryHelper::escape($context->getAlias() . '.parent'),
        ];

        
$alias = $this->callResolver($resolverContext);

            if (!$field instanceof AssociationField) {
                return;
            }

            $definition = $field->getReferenceDefinition();
            if ($field instanceof ManyToManyAssociationField) {
                $definition = $field->getToManyReferenceDefinition();
            }

            if ($definition->isInheritanceAware() && $context->considerInheritance() && $parent = $definition->getField('parent')) {
                $resolverContext = new FieldResolverContext($currentPath$alias$parent$definition$rootDefinition$query$context$criteriaPart);

                $this->callResolver($resolverContext);
            }
        }
    }

    public function resolveField(Field $field, EntityDefinition $definition, string $root, QueryBuilder $query, Context $context): void
    {
        $resolver = $field->getResolver();

        
if (!$scriptAppInformation) {
            return $hook->getContext();
        }

        return new Context(
            $this->getAppContextSource($scriptAppInformation),
            $hook->getContext()->getRuleIds(),
            $hook->getContext()->getCurrencyId(),
            $hook->getContext()->getLanguageIdChain(),
            $hook->getContext()->getVersionId(),
            $hook->getContext()->getCurrencyFactor(),
            $hook->getContext()->considerInheritance(),
            $hook->getContext()->getTaxState(),
            $hook->getContext()->getRounding()
        );
    }

    private function getAppContextSource(ScriptAppInformation $scriptAppInformation): AdminApiSource
    {
        if (\array_key_exists($scriptAppInformation->getAppId()$this->appSources)) {
            return $this->appSources[$scriptAppInformation->getAppId()];
        }

        
$fkVersionId = \substr($field->getReferenceField(), 0, -3) . '_version_id';
        if ($reference->getFields()->getByStorageName($fkVersionId)) {
            return ' AND #root#.version_id = #alias#.' . $fkVersionId;
        }

        return ' AND #root#.version_id = #alias#.version_id';
    }

    private function getSourceColumn(FieldResolverContext $context, OneToManyAssociationField $field): string
    {
        if ($field->is(Inherited::class) && $context->getContext()->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($context->getAlias()) . '.' . EntityDefinitionQueryHelper::escape($field->getPropertyName());
        }

        return EntityDefinitionQueryHelper::escape($context->getAlias()) . '.' . EntityDefinitionQueryHelper::escape($field->getLocalField());
    }

    private function getReferenceColumn(FieldResolverContext $context, OneToManyAssociationField $field): string
    {
        if ($field->is(ReverseInherited::class) && $context->getContext()->considerInheritance()) {
            /** @var ReverseInherited $flag */
            $flag = $field->getFlag(ReverseInherited::class);

            
private readonly CriteriaPartResolver $criteriaPartResolver
    ) {
    }

    /** * @param list<string> $paths */
    public function build(QueryBuilder $query, EntityDefinition $definition, Criteria $criteria, Context $context, array $paths = []): QueryBuilder
    {
        $query = $this->helper->getBaseQuery($query$definition$context);

        if ($definition->isInheritanceAware() && $context->considerInheritance()) {
            $parent = $definition->getFields()->get('parent');

            if ($parent) {
                $this->helper->resolveField($parent$definition$definition->getEntityName()$query$context);
            }
        }

        if ($criteria->getTerm()) {
            $pattern = $this->interpreter->interpret((string) $criteria->getTerm());
            $queries = $this->scoreBuilder->buildScoreQueries($pattern$definition$definition->getEntityName()$context);
            $criteria->addQuery(...$queries);
        }
$version = Uuid::fromHexToBytes(Defaults::LIVE_VERSION);

        $filter = json_decode((string) $filter, true, 512, \JSON_THROW_ON_ERROR);

        $criteria = $this->getCriteria($filter);

        if ($criteria === null) {
            return;
        }

        $criteria->setLimit(150);
        $considerInheritance = $message->getContext()->considerInheritance();
        $message->getContext()->setConsiderInheritance(true);

        $iterator = new RepositoryIterator(
            $this->repository,
            $message->getContext(),
            $criteria
        );

        $binary = Uuid::fromHexToBytes($id);

        $ids = $this->connection->fetchFirstColumn(
            
protected function getSourceColumn(EntityDefinition $definition, AssociationField $field, string $root, Context $context): string
    {
        if (!$field instanceof ManyToOneAssociationField && !$field instanceof OneToOneAssociationField) {
            throw new \RuntimeException('Expected field of type ManyToOneAssociationField or OneToOneAssociationField');
        }

        if (!$field->is(Inherited::class)) {
            return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getStorageName());
        }

        if (!$context->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getStorageName());
        }

        $inherited = EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getPropertyName());

        $fk = $definition->getFields()->getByStorageName($field->getStorageName());

        if (!$fk) {
            throw new \RuntimeException(sprintf('Can not find foreign key for table column %s.%s', $definition->getEntityName()$field->getStorageName()));
        }

        
static::assertInstanceOf(Entity::class$p1);
        static::assertInstanceOf(Entity::class$p2);
        static::assertInstanceOf(Entity::class$p3);

        $proxies = [
            $ids->get('p1') => new ProductProxy($p1$salesChannelContext$stubs),
            $ids->get('p2') => new ProductProxy($p2$salesChannelContext$stubs),
            $ids->get('p3.1') => new ProductProxy($p3$salesChannelContext$stubs),
        ];

        $salesChannelContext->considerInheritance();
        $hook = new ProductPricingHookExtension($proxies$salesChannelContext$ids);

        // allows easy debugging         $traces = new ScriptTraces();

        $loader = $this->createMock(ScriptLoader::class);
        $loader->method('get')->willReturn([
            new Script('foo', (string) \file_get_contents(__DIR__ . '/_fixtures/pricing-cases/product-pricing.twig')new \DateTimeImmutable()),
        ]);

        $executor = new ScriptExecutor($loadernew NullLogger()$traces$this->getContainer()$this->getContainer()->get('twig.extension.trans'), 'v6.5.0.0');

        
private function createDeContext(Context $enContext): Context
    {
        $deLanguageId = $this->getDeDeLanguageId();

        return new Context(
            $enContext->getSource(),
            $enContext->getRuleIds(),
            $enContext->getCurrencyId(),
            [$deLanguageId$enContext->getLanguageId()],
            $enContext->getVersionId(),
            $enContext->getCurrencyFactor(),
            $enContext->considerInheritance(),
            $enContext->getTaxState()
        );
    }

    private function getTestTranslations(string $prefix = ''): array
    {
        $translations = [];
        foreach ($this->languages as $locale) {
            $translations[$locale] = ['name' => $prefix . 'original-' . $locale];
        }

        
if (!$field instanceof AssociationField) {
                return;
            }

            $definition = $field->getReferenceDefinition();
            if ($field instanceof ManyToManyAssociationField) {
                $definition = $field->getToManyReferenceDefinition();
            }

            $parent = $definition->getField('parent');
            if ($parent && $definition->isInheritanceAware() && $context->considerInheritance()) {
                $resolverContext = new FieldResolverContext($currentPath$alias$parent$definition$rootDefinition$query$context$criteriaPart);

                $this->callResolver($resolverContext);
            }
        }
    }

    private function callResolver(FieldResolverContext $context): string
    {
        $resolver = $context->getField()->getResolver();

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