Skip to content

Commit

Permalink
Merge branch 'next-34411/auto-imported-from-github' into 'trunk'
Browse files Browse the repository at this point in the history
NEXT-34411 - NEXT-29093 - Fix theme config label inheritance

See merge request shopware/6/product/platform!13368
  • Loading branch information
ssltg committed Mar 20, 2024
2 parents f36ebe8 + e2e964b commit 57178bc
Show file tree
Hide file tree
Showing 4 changed files with 788 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Fix theme config label inheritance
issue: NEXT-29093
author: Elias Lackner
author_email: [email protected]
author_github: @lacknere
---
# Storefront
* Changed `getConfigInheritance` method of `ThemeService` to add default `@Storefront` inheritance in case nothing else is configured.
* Changed `getTranslations` method of `ThemeService` to work for themes without a `parentThemeId` to get translations of the default Storefront theme.
10 changes: 8 additions & 2 deletions src/Storefront/Theme/ThemeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private function getParentThemes(ThemeCollection $themes, ThemeEntity $mainTheme
}

/**
* @return array<string, mixed>
* @return array<int, string>
*/
private function getConfigInheritance(ThemeEntity $mainTheme): array
{
Expand All @@ -430,6 +430,12 @@ private function getConfigInheritance(ThemeEntity $mainTheme): array
return $mainTheme->getBaseConfig()['configInheritance'];
}

if ($mainTheme->getTechnicalName() !== StorefrontPluginRegistry::BASE_THEME_NAME) {
return [
'@' . StorefrontPluginRegistry::BASE_THEME_NAME,
];
}

return [];
}

Expand Down Expand Up @@ -584,7 +590,7 @@ private function getTranslations(string $themeId, Context $context): array

$translations = $theme->getLabels() ?: [];

if ($theme->getParentThemeId()) {
if ($theme->getTechnicalName() !== StorefrontPluginRegistry::BASE_THEME_NAME) {
$criteria = new Criteria();
$criteria->setTitle('theme-service::load-translations');

Expand Down
195 changes: 192 additions & 3 deletions tests/unit/Storefront/Theme/ThemeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ public static function getThemeCollectionForThemeConfiguration(): array
[
(new ThemeEntity())->assign(
[
'id' => $themeId,
'_uniqueIdentifier' => $themeId,
'salesChannels' => new SalesChannelCollection(),
'configValues' => [
Expand All @@ -1176,8 +1177,9 @@ public static function getThemeCollectionForThemeConfiguration(): array
),
(new ThemeEntity())->assign(
[
'id' => $baseThemeId,
'technicalName' => StorefrontPluginRegistry::BASE_THEME_NAME,
'_uniqueIdentifier' => Uuid::randomHex(),
'_uniqueIdentifier' => $baseThemeId,
]
),
]
Expand Down Expand Up @@ -1205,15 +1207,17 @@ public static function getThemeCollectionForThemeConfiguration(): array
[
(new ThemeEntity())->assign(
[
'id' => $themeId,
'_uniqueIdentifier' => $themeId,
'salesChannels' => new SalesChannelCollection(),
'configValues' => [],
]
),
(new ThemeEntity())->assign(
[
'id' => $baseThemeId,
'technicalName' => StorefrontPluginRegistry::BASE_THEME_NAME,
'_uniqueIdentifier' => Uuid::randomHex(),
'_uniqueIdentifier' => $baseThemeId,
'configValues' => [
'test' => ['value' => ['no_test']],
],
Expand Down Expand Up @@ -1244,6 +1248,7 @@ public static function getThemeCollectionForThemeConfiguration(): array
[
(new ThemeEntity())->assign(
[
'id' => $themeId,
'_uniqueIdentifier' => $themeId,
'salesChannels' => new SalesChannelCollection(),
'baseConfig' => [
Expand All @@ -1259,8 +1264,9 @@ public static function getThemeCollectionForThemeConfiguration(): array
),
(new ThemeEntity())->assign(
[
'id' => $baseThemeId,
'technicalName' => StorefrontPluginRegistry::BASE_THEME_NAME,
'_uniqueIdentifier' => Uuid::randomHex(),
'_uniqueIdentifier' => $baseThemeId,
'configValues' => [
'test' => ['value' => ['no_test']],
],
Expand All @@ -1284,6 +1290,189 @@ public static function getThemeCollectionForThemeConfiguration(): array
'tabs' => ThemeFixtures::getExtractedTabs9(),
],
],
[
'ids' => [
'themeId' => $themeId,
'parentThemeId' => $parentThemeId,
'baseThemeId' => $baseThemeId,
],
'themeCollection' => new ThemeCollection(
[
(new ThemeEntity())->assign(
[
'id' => $themeId,
'technicalName' => 'Theme',
'_uniqueIdentifier' => $themeId,
'baseConfig' => [
'fields' => [
'sw-color-brand-primary' => [
'value' => '#adbd00',
],
],
],
]
),
(new ThemeEntity())->assign(
[
'id' => $baseThemeId,
'technicalName' => StorefrontPluginRegistry::BASE_THEME_NAME,
'_uniqueIdentifier' => $baseThemeId,
'baseConfig' => ThemeFixtures::getThemeJsonConfig(),
'labels' => [
'blocks.media' => 'Media',
'blocks.eCommerce' => 'E-Commerce',
'blocks.unordered' => 'Misc',
'blocks.typography' => 'Typography',
'blocks.themeColors' => 'Theme colours',
'blocks.statusColors' => 'Status messages',
'fields.sw-color-info' => 'Information',
'fields.sw-logo-share' => 'App & share icon',
'fields.sw-text-color' => 'Text colour',
'fields.sw-color-price' => 'Price',
'fields.sw-logo-mobile' => 'Mobile',
'fields.sw-logo-tablet' => 'Tablet',
'fields.sw-border-color' => 'Border',
'fields.sw-color-danger' => 'Error',
'fields.sw-logo-desktop' => 'Desktop',
'fields.sw-logo-favicon' => 'Favicon',
'fields.sw-color-success' => 'Success',
'fields.sw-color-warning' => 'Notice',
'fields.sw-headline-color' => 'Headline colour',
'fields.sw-background-color' => 'Background',
'fields.sw-color-buy-button' => 'Buy button',
'fields.sw-font-family-base' => 'Fonttype text',
'fields.sw-color-brand-primary' => 'Primary colour',
'fields.sw-font-family-headline' => 'Fonttype headline',
'fields.sw-color-brand-secondary' => 'Secondary colour',
'fields.sw-color-buy-button-text' => 'Buy button text',
],
'helpTexts' => [
'fields.sw-logo-mobile' => 'Displayed up to a viewport of 767px',
'fields.sw-logo-tablet' => 'Displayed between a viewport of 767px to 991px',
'fields.sw-logo-desktop' => 'Displayed on viewport sizes above 991px and as a fallback on smaller viewports, if no other logo is set.',
],
]
),
]
),
'expected' => [
'blocks' => ThemeFixtures::getExtractedBlock1(),
'fields' => ThemeFixtures::getExtractedFields10(),
'currentFields' => ThemeFixtures::getExtractedCurrentFields6(),
'baseThemeFields' => ThemeFixtures::getExtractedBaseThemeFields6(),
],
'expectedNotTranslated' => [
'blocks' => ThemeFixtures::getExtractedBlock1(),
'fields' => ThemeFixtures::getExtractedFields9(),
'currentFields' => ThemeFixtures::getExtractedCurrentFields6(),
'baseThemeFields' => ThemeFixtures::getExtractedBaseThemeFields6(),
],
'expectedStructured' => [
'tabs' => ThemeFixtures::getExtractedTabs12(),
],
'expectedStructuredNotTranslated' => [
'tabs' => ThemeFixtures::getExtractedTabs13(),
],
],
[
'ids' => [
'themeId' => $themeId,
'parentThemeId' => $parentThemeId,
'baseThemeId' => $baseThemeId,
],
'themeCollection' => new ThemeCollection(
[
(new ThemeEntity())->assign(
[
'id' => $themeId,
'_uniqueIdentifier' => $themeId,
'salesChannels' => new SalesChannelCollection(),
'parentThemeId' => $parentThemeId,
'baseConfig' => [
'fields' => [
'sw-color-brand-secondary' => [
'value' => '#46801a',
],
],
],
]
),
(new ThemeEntity())->assign(
[
'id' => $parentThemeId,
'technicalName' => 'Theme',
'_uniqueIdentifier' => $parentThemeId,
'baseConfig' => [
'fields' => [
'sw-color-brand-primary' => [
'value' => '#adbd00',
],
],
],
]
),
(new ThemeEntity())->assign(
[
'id' => $baseThemeId,
'technicalName' => StorefrontPluginRegistry::BASE_THEME_NAME,
'_uniqueIdentifier' => $baseThemeId,
'baseConfig' => ThemeFixtures::getThemeJsonConfig(),
'labels' => [
'blocks.media' => 'Media',
'blocks.eCommerce' => 'E-Commerce',
'blocks.unordered' => 'Misc',
'blocks.typography' => 'Typography',
'blocks.themeColors' => 'Theme colours',
'blocks.statusColors' => 'Status messages',
'fields.sw-color-info' => 'Information',
'fields.sw-logo-share' => 'App & share icon',
'fields.sw-text-color' => 'Text colour',
'fields.sw-color-price' => 'Price',
'fields.sw-logo-mobile' => 'Mobile',
'fields.sw-logo-tablet' => 'Tablet',
'fields.sw-border-color' => 'Border',
'fields.sw-color-danger' => 'Error',
'fields.sw-logo-desktop' => 'Desktop',
'fields.sw-logo-favicon' => 'Favicon',
'fields.sw-color-success' => 'Success',
'fields.sw-color-warning' => 'Notice',
'fields.sw-headline-color' => 'Headline colour',
'fields.sw-background-color' => 'Background',
'fields.sw-color-buy-button' => 'Buy button',
'fields.sw-font-family-base' => 'Fonttype text',
'fields.sw-color-brand-primary' => 'Primary colour',
'fields.sw-font-family-headline' => 'Fonttype headline',
'fields.sw-color-brand-secondary' => 'Secondary colour',
'fields.sw-color-buy-button-text' => 'Buy button text',
],
'helpTexts' => [
'fields.sw-logo-mobile' => 'Displayed up to a viewport of 767px',
'fields.sw-logo-tablet' => 'Displayed between a viewport of 767px to 991px',
'fields.sw-logo-desktop' => 'Displayed on viewport sizes above 991px and as a fallback on smaller viewports, if no other logo is set.',
],
]
),
]
),
'expected' => [
'blocks' => ThemeFixtures::getExtractedBlock1(),
'fields' => ThemeFixtures::getExtractedFields12(),
'currentFields' => ThemeFixtures::getExtractedCurrentFields7(),
'baseThemeFields' => ThemeFixtures::getExtractedBaseThemeFields7(),
],
'expectedNotTranslated' => [
'blocks' => ThemeFixtures::getExtractedBlock1(),
'fields' => ThemeFixtures::getExtractedFields11(),
'currentFields' => ThemeFixtures::getExtractedCurrentFields7(),
'baseThemeFields' => ThemeFixtures::getExtractedBaseThemeFields7(),
],
'expectedStructured' => [
'tabs' => ThemeFixtures::getExtractedTabs12(),
],
'expectedStructuredNotTranslated' => [
'tabs' => ThemeFixtures::getExtractedTabs13(),
],
],
];
}
}
Loading

0 comments on commit 57178bc

Please sign in to comment.