getLanguageIdChain example

$context = Context::createDefaultContext();

        $this->productRepository->create($product$context);

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('product.price', 8.0));

        $searchContext = new Context(
            new SystemSource(),
            $context->getRuleIds(),
            Uuid::randomHex(),
            $context->getLanguageIdChain(),
            $context->getVersionId(),
            0.8
        );

        $products = $this->productRepository->search($criteria$searchContext);
        static::assertSame(1, $products->getTotal());

        /** @var ProductEntity $product */
        $product = $products->get($productId);
        static::assertInstanceOf(ProductEntity::class$product);
    }

    
public function getAppContext(Hook $hook, Script $script): Context
    {
        $scriptAppInformation = $script->getScriptAppInformation();
        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)) {
            
/** * @param array<string, mixed> $stored * @param array<string, mixed> $data */
    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);

            
$context->setConsiderInheritance(true);

        /** @var ProductEntity $product */
        $product = $this->getContainer()
            ->get('product.repository')
            ->search(new Criteria([$id])$context)->first();

        static::assertTrue($context->considerInheritance());
        static::assertSame($name$product->getTranslated()['name']sprintf(
            'Expected %s with language chain %s but got %s, version context: %s',
            $name,
            (string) print_r($context->getLanguageIdChain(), true),
            $product->getName(),
            $context->getVersionId() === Defaults::LIVE_VERSION ? 'NO' : 'YES'
        ));

        $context->setConsiderInheritance(false);
    }

    private function createParentChildProduct(bool $addChildTranslations = true): IdsCollection
    {
        $context = Context::createDefaultContext();
        $ids = new IdsCollection();

        
        $taxRules = $this->getTaxRules($base$customer$shippingLocation);

        // detect active payment method, first check if checkout defined other payment method, otherwise validate if customer logged in, at least use shop default         $payment = $this->getPaymentMethod($options$base$customer);

        [$itemRounding$totalRounding] = $this->getCashRounding($base$shippingLocation);

        $context = new Context(
            $base->getContext()->getSource(),
            [],
            $base->getCurrencyId(),
            $base->getContext()->getLanguageIdChain(),
            $base->getContext()->getVersionId(),
            $base->getCurrency()->getFactor(),
            true,
            CartPrice::TAX_STATE_GROSS,
            $itemRounding
        );

        $salesChannelContext = new SalesChannelContext(
            $context,
            $token,
            $options[SalesChannelContextService::DOMAIN_ID] ?? null,
            
return $this->createActionResponse($request);
        }

        try {
            $token = $this->loginRoute->login($data$context)->getToken();
            $cartBeforeNewContext = $this->cartFacade->get($token$context);

            $newContext = $this->salesChannelContextService->get(
                new SalesChannelContextServiceParameters(
                    $context->getSalesChannelId(),
                    $token,
                    $context->getLanguageIdChain()[0],
                    $context->getCurrencyId(),
                    $context->getDomainId(),
                    $context->getContext()
                )
            );

            // Update the sales channel context for CacheResponseSubscriber             $request->attributes->set(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT, $newContext);

            if (!empty($token)) {
                $this->addCartErrors($cartBeforeNewContext);

                


        return $field;
    }

    /** * @return list<string> */
    public static function buildTranslationChain(string $root, Context $context, bool $includeParent): array
    {
        $chain = [];
        $count = \count($context->getLanguageIdChain()) - 1;

        for ($i = $count$i >= 1; --$i) {
            $chain[] = $root . '.translation.fallback_' . $i;
            if ($includeParent) {
                $chain[] = $root . '.parent.translation.fallback_' . $i;
            }
        }

        $chain[] = $root . '.translation';
        if ($includeParent) {
            $chain[] = $root . '.parent.translation';
        }
public function resolve(Request $request): void
    {
        if ($request->attributes->has(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT)) {
            return;
        }

        if (!$this->isRequestScoped($request, ApiContextRouteScopeDependant::class)) {
            return;
        }

        $params = $this->getContextParameters($request);
        $languageIdChain = $this->getLanguageIdChain($params);

        $rounding = $this->getCashRounding($params['currencyId']);

        $context = new Context(
            $this->resolveContextSource($request),
            [],
            $params['currencyId'],
            $languageIdChain,
            $params['versionId'] ?? Defaults::LIVE_VERSION,
            $params['currencyFactory'],
            $params['considerInheritance'],
            
public function getDecorated(): AbstractProductSearchQueryBuilder
    {
        throw new DecorationPatternException(self::class);
    }

    /** * @return array<SearchConfig> */
    private function fetchConfig(Context $context): array
    {
        foreach ($context->getLanguageIdChain() as $languageId) {
            /** @var array<SearchConfig> $config */
            $config = $this->connection->fetchAllAssociative(
                'SELECT product_search_config.and_logic, product_search_config_field.field, product_search_config_field.tokenize, product_search_config_field.ranking FROM product_search_config INNER JOIN product_search_config_field ON(product_search_config_field.product_search_config_id = product_search_config.id) WHERE product_search_config.language_id = :languageId AND product_search_config_field.searchable = 1 AND product_search_config_field.field NOT IN(:excludedFields)',
                [
string $on,
        Context $context,
        ?string $versionFieldName = null,
    ): QueryBuilder {
        $table = $definition->getEntityName() . '_translation';

        $query = new QueryBuilder($this->connection);

        $select = $this->getSelectTemplate($translationDefinition);

        // first language has to be the "from" part, in this case we have to use the system language to enforce we have a record         $chain = array_reverse($context->getLanguageIdChain());

        $first = array_shift($chain);
        $firstAlias = $on . '.translation';

        $foreignKey = EntityDefinitionQueryHelper::escape($firstAlias) . '.' . $definition->getEntityName() . '_id';

        // used as join condition         $query->addSelect($foreignKey);

        if ($versionFieldName !== null) {
            $versionKey = EntityDefinitionQueryHelper::escape($firstAlias) . '.' . $versionFieldName;
            
/** * @param string[] $areas */
    public function getSalesChannelContextHash(SalesChannelContext $context, array $areas = []): string
    {
        $ruleIds = $context->getRuleIdsByAreas($areas);

        return md5((string) json_encode([
            $context->getSalesChannelId(),
            $context->getDomainId(),
            $context->getLanguageIdChain(),
            $context->getVersionId(),
            $context->getCurrencyId(),
            $context->getTaxState(),
            $context->getItemRounding(),
            $ruleIds,
        ], \JSON_THROW_ON_ERROR));
    }

    public function getCriteriaHash(Criteria $criteria): string
    {
        return md5((string) json_encode([
            
public function setDomainId(?string $domainId): void
    {
        $this->domainId = $domainId;
    }

    /** * @return string[] */
    public function getLanguageIdChain(): array
    {
        return $this->context->getLanguageIdChain();
    }

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

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

    
        $payment = $this->getPaymentMethod($options$context$salesChannel);

        // detect active delivery method, at first checkout scope, at least shop default method         $shippingMethod = $this->getShippingMethod($options$context$salesChannel);

        [$itemRounding$totalRounding] = $this->getCashRounding($currency$shippingLocation$context);

        $context = new Context(
            $context->getSource(),
            [],
            $currency->getId(),
            $context->getLanguageIdChain(),
            $context->getVersionId(),
            $currency->getFactor(),
            true,
            CartPrice::TAX_STATE_GROSS,
            $itemRounding
        );

        return new BaseContext(
            $context,
            $salesChannel,
            $currency,
            
SQL;

        $data = $this->connection->fetchAllAssociative(
            $sql,
            [
                'ids' => $ids,
                'languageIds' => Uuid::fromHexToBytesList($context->getLanguageIdChain()),
                'liveVersionId' => Uuid::fromHexToBytes($context->getVersionId()),
            ],
            [
                'ids' => ArrayParameterType::STRING,
                'languageIds' => ArrayParameterType::STRING,
            ]
        );

        return FetchModeHelper::groupUnique($data);
    }

    
if (!$order instanceof OrderEntity) {
            throw OrderException::orderNotFound($orderId);
        }

        /** @var CashRoundingConfig $itemRounding */
        $itemRounding = $order->getItemRounding();

        $orderContext = new Context(
            $context->getSource(),
            $order->getRuleIds() ?? [],
            $order->getCurrencyId(),
            array_values(array_unique(array_merge([$order->getLanguageId()]$context->getLanguageIdChain()))),
            $context->getVersionId(),
            $order->getCurrencyFactor(),
            true,
            $order->getTaxStatus(),
            $itemRounding
        );

        $orderContext->addState(...$context->getStates());
        $orderContext->addExtensions($context->getExtensions());

        return $orderContext;
    }
Home | Imprint | This part of the site doesn't use cookies.