injectSettings example



        $context = $this->salesChannelContextService->get(
            new SalesChannelContextServiceParameters(
                $productExport->getStorefrontSalesChannelId(),
                $contextToken,
                $productExport->getSalesChannelDomain()->getLanguageId(),
                $productExport->getSalesChannelDomain()->getCurrencyId() ?? $productExport->getCurrencyId()
            )
        );

        $this->translator->injectSettings(
            $productExport->getStorefrontSalesChannelId(),
            $productExport->getSalesChannelDomain()->getLanguageId(),
            $this->languageLocaleProvider->getLocaleForLanguageId($productExport->getSalesChannelDomain()->getLanguageId()),
            $context->getContext()
        );

        $headerContent = $this->productExportRender->renderHeader($productExport$context);
        $footerContent = $this->productExportRender->renderFooter($productExport$context);
        $finalFilePath = $this->productExportFileHandler->getFilePath($productExport);

        $this->translator->resetInjection();

        
private function injectTranslator(Context $context, ?string $salesChannelId): bool
    {
        if ($salesChannelId === null) {
            return false;
        }

        if ($this->translator->getSnippetSetId() !== null) {
            return false;
        }

        $this->translator->injectSettings(
            $salesChannelId,
            $context->getLanguageId(),
            $this->languageLocaleProvider->getLocaleForLanguageId($context->getLanguageId()),
            $context
        );

        return true;
    }

    /** * @param array<string, mixed> $recipients * @param array<string, string> $mailStructRecipients * @param array<int|string, mixed> $contactFormData * * @return array<int|string, string> */
        $this->loadAppsFromDir(__DIR__ . '/Fixtures/theme');
        $this->reloadAppSnippets();

        // Ensure the default Storefront theme is active         $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('technicalName', 'Storefront'));
        $defaultThemeId = $themeRepo->searchIds($criteria$salesChannelContext->getContext())->firstId();
        static::assertNotNull($defaultThemeId, 'Default theme not found');
        $themeService->assignTheme($defaultThemeId$salesChannelContext->getSalesChannelId()$salesChannelContext->getContext(), true);

        // Inject the sales channel and assert that the original snippet is used         $translator->injectSettings(
            $salesChannelContext->getSalesChannelId(),
            $salesChannelContext->getLanguageId(),
            'en-GB',
            $salesChannelContext->getContext()
        );

        static::assertEquals('Service date equivalent to invoice date', $translator->trans('document.serviceDateNotice'));

        $translator->reset();
        $themeLoader->reset();

        
$property->setAccessible(true);
        $property->setValue($item, true);

        $cache->expects($expectedCacheKey ? static::once() : static::never())->method('get')->willReturnCallback(function Dstring $key, callable $callback) use ($expectedCacheKey$item) {
            static::assertEquals($expectedCacheKey$key);

            /** @var callable(CacheItem): mixed $callback */
            return $callback($item);
        });

        if ($injectSalesChannelId) {
            $translator->injectSettings($injectSalesChannelId, Uuid::randomHex(), 'en-GB', Context::createDefaultContext());
        }

        $snippetSetIdProp = (new \ReflectionClass($translator))->getProperty('snippetSetId');
        $snippetSetIdProp->setAccessible(true);
        $snippetSetIdProp->setValue($translator$snippetSetId);

        // No snippet is added         if ($expectedCacheKey === null) {
            $catalogue = $translator->getCatalogue('en-GB');

            static::assertSame($originCatalogue$catalogue);

            

    public function render(
        string $view,
        array $parameters = [],
        ?Context $context = null,
        ?string $salesChannelId = null,
        ?string $languageId = null,
        ?string $locale = null
    ): string {
        // If parameters for specific language setting provided, inject to translator         if ($context !== null && $salesChannelId !== null && $languageId !== null && $locale !== null) {
            $this->translator->injectSettings(
                $salesChannelId,
                $languageId,
                $locale,
                $context
            );
            $salesChannelContext = $this->contextFactory->create(
                Uuid::randomHex(),
                $salesChannelId,
                [SalesChannelContextService::LANGUAGE_ID => $languageId]
            );

            

        $this->getDecorated()->reset();
    }

    public function resetInjection(): void
    {
        $this->getDecorated()->resetInjection();
    }

    public function injectSettings(string $salesChannelId, string $languageId, string $locale, Context $context): void
    {
        $this->getDecorated()->injectSettings($salesChannelId$languageId$locale$context);
    }

    public function getSnippetSetId(?string $locale = null): ?string
    {
        return $this->getDecorated()->getSnippetSetId($locale);
    }

    abstract public function getDecorated(): AbstractTranslator;

    /** * @template TReturn of mixed * * @param \Closure(): TReturn $param * * @return TReturn All kind of data could be cached */


        $context = $this->salesChannelContextService->get(
            new SalesChannelContextServiceParameters(
                $productExport->getStorefrontSalesChannelId(),
                $contextToken,
                $productExport->getSalesChannelDomain()->getLanguageId(),
                $productExport->getCurrencyId()
            )
        );

        $this->translator->injectSettings(
            $productExport->getStorefrontSalesChannelId(),
            $productExport->getSalesChannelDomain()->getLanguageId(),
            $this->languageLocaleProvider->getLocaleForLanguageId($productExport->getSalesChannelDomain()->getLanguageId()),
            $context->getContext()
        );

        $filters = $this->productStreamBuilder->buildFilters(
            $productExport->getProductStreamId(),
            $context->getContext()
        );

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