getStorefrontSnippets example


    private function loadSnippets(MessageCatalogueInterface $catalog, string $snippetSetId, ?string $fallbackLocale): array
    {
        $this->resolveSalesChannelId();

        $key = sprintf('translation.catalog.%s.%s', $this->salesChannelId ?: 'DEFAULT', $snippetSetId);

        return $this->cache->get($keyfunction DItemInterface $item) use ($catalog$snippetSetId$fallbackLocale) {
            $item->tag('translation.catalog.' . $snippetSetId);
            $item->tag(sprintf('translation.catalog.%s', $this->salesChannelId ?: 'DEFAULT'));

            return $this->snippetService->getStorefrontSnippets($catalog$snippetSetId$fallbackLocale$this->salesChannelId);
        });
    }

    private function getFallbackLocale(): string
    {
        try {
            return $this->languageLocaleProvider->getLocaleForLanguageId(Defaults::LANGUAGE_SYSTEM);
        } catch (ConnectionException) {
            // this allows us to use the translator even if there's no db connection yet             return 'en-GB';
        }
    }
$this->snippetCollection,
            $this->createMock(EntityRepository::class),
            $this->createMock(EntityRepository::class),
            $this->createMock(EntityRepository::class),
            $this->createMock(SnippetFilterFactory::class),
            $container,
            $themeLoader,
        );

        $catalog = new MessageCatalogue((string) $fetchLocaleResult['messages' => $catalogMessages]);

        $snippets = $snippetService->getStorefrontSnippets($catalog, Uuid::randomHex()$fallbackLocale$salesChannelId);

        static::assertEquals($expected$snippets);
    }

    public function testGetStorefrontSnippetsWithoutThemeRegistry(): void
    {
        $locale = 'de-DE';
        $snippetSetId = Uuid::randomHex();
        $catalog = new MessageCatalogue($locale[]);

        $container = $this->createMock(ContainerInterface::class);
        
protected function tearDown(): void
    {
        MockSnippetFile::cleanup();
    }

    public function testGetStorefrontSnippetsForNotExistingSnippetSet(): void
    {
        $this->expectException(\InvalidArgumentException::class);

        $service = $this->getSnippetService();

        $service->getStorefrontSnippets($this->getCatalog([], 'en-GB'), Uuid::randomHex());
    }

    public function testGetRegionFilterItems(): void
    {
        $snippetFile = new MockSnippetFile(
            'foo',
            'foo',
            <<<json { "foo": { "baz": "foo_baz", "bas": "foo_bas" }, "bar": { "zz": "bar_zz" } }
Home | Imprint | This part of the site doesn't use cookies.