Shopware 6, Deployer and broken themes
Fabian Blechschmidt
We run deployer to deployer our Shopware 6 shops in combination with shopware-cli and Shopware’s deployment-helper. But we had one problem, during deployment the old theme breaks, because compiling the theme regenerates the themeSeed on the database and the new theme is generated in another directory than the old theme.
We thought about using Shopware’s MD5ThemePathBuilder, but my fear is, that we get trouble with browser caching, because the url doesn’t change. So I thought we implement our own ThemePathBuilder: the StaticThemePathBuilder.
https://github.com/winkelwagen-de/sw6-plugin-static-theme-path-builder
The idea is simple: We don’t want to depend on the database and we don’t want to have the same path everywhere, so what about depending on the root directory of Shopware? And because getting the root is not so simple, we just do realpath(__FILE__).
class StaticPathThemePathBuilder extends AbstractThemePathBuilder
{
public function assemblePath(string $salesChannelId, string $themeId): string
{
$path = realpath(__FILE__);
return $this->generateNewPath($salesChannelId, $themeId, $path);
}
public function generateNewPath(string $salesChannelId, string $themeId, string $seed): string
{
return Hasher::hash($themeId . $salesChannelId . $seed);
}
public function saveSeed(string $salesChannelId, string $themeId, string $seed): void
{
// no need to save a seed, we use the realpath of installation
}
public function getDecorated(): AbstractThemePathBuilder
{
throw new DecorationPatternException(self::class);
}
}
We hope the plugin helps you. If you have any questions or improvements, feel free to drop us an email or open an issue!
Other articles from this category