ThemeCollection example

 $parameters);
    }

    public function testUpdateThemeNoTheme(): void
    {
        $themeId = Uuid::randomHex();

        $this->themeRepositoryMock->method('search')->willReturn(
            new EntitySearchResult(
                'theme',
                1,
                new ThemeCollection(
                    [
                        (new ThemeEntity())->assign(
                            [
                                '_uniqueIdentifier' => 'no',
                                'salesChannels' => new SalesChannelCollection(),
                            ]
                        ),
                    ]
                ),
                null,
                new Criteria(),
                
public function testThemeProviderReturnsIdsOfFoundSalesChannelsWithThemes(): void
    {
        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId('sales-channel-with-theme');
        $salesChannel->setUniqueIdentifier('sales-channel-with-theme');

        $theme = new ThemeEntity();
        $theme->setId('associated-theme');
        $theme->setUniqueIdentifier('associated-theme');

        $salesChannel->addExtension('themes', new ThemeCollection([$theme]));

        $themeProvider = new DatabaseAvailableThemeProvider(new StaticEntityRepository([
            new SalesChannelCollection([$salesChannel]),
        ]));

        static::assertEquals(
            ['sales-channel-with-theme' => 'associated-theme'],
            $themeProvider->load(Context::createDefaultContext(), false),
        );
    }

    
$criteria = new Criteria();
        $criteria->addAssociation('dependentThemes');
        $criteria->addFilter(new EqualsFilter('technicalName', $technicalName));

        /** @var ThemeEntity|null $theme */
        $theme = $this->themeRepository->search($criteria$context)->first();

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

        $dependentThemes = $theme->getDependentThemes() ?? new ThemeCollection();
        $ids = [...array_values($dependentThemes->getIds()), ...[$theme->getId()]];

        $this->removeOldMedia($technicalName$context);
        $this->themeRepository->delete(array_map(fn (string $id) => ['id' => $id]$ids)$context);
    }

    private function getThemeByTechnicalName(string $technicalName, Context $context): ?ThemeEntity
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('technicalName', $technicalName));
        $criteria->addAssociation('previewMedia');

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