Ich habe mir dafür ein kleines Shopware 5.2 Plugin geschrieben. Ohne Gewähr:
Datei custom/plugins/Cdn/Cdn.php:
Datei custom/plugins/Cdn/Subscriber/Cdn.php
cdnConfig = $cdnConfig;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'Enlight_Plugins_ViewRenderer_FilterRender' => 'onFilterRender'
];
}
/**
* @param Enlight_Event_EventArgs $args
*
* @return string
*/
public function onFilterRender(Enlight_Event_EventArgs $args)
{
$content = $args->getReturn();
if (false === isset($this->cdnConfig['backend']) || 'local' !== $this->cdnConfig['backend']) {
return $content;
}
if (true === isset($this->cdnConfig['adapters']['local']['replace'])) {
$keys = array_keys($this->cdnConfig['adapters']['local']['replace']);
$values = array_values($this->cdnConfig['adapters']['local']['replace']);
$content = str_replace($keys, $values, $content);
}
return $content;
}
}
Datei custom/plugins/Cdn/Resources/services.xml
%shopware.cdn%
Datei config.php (replace ggf. erweitern bzw. mit anderen Werten arbeiten)
$cdn = 'https://www.test.com';
$config['cdn'] = [
'backend' => 'local',
'adapters' => [
'local' => [
'type' => 'local',
'mediaUrl' => $cdn .'/',
'path' => realpath( __DIR__. '/'),
'replace' => [
'href="/web/cache/' => 'href="' . $cdn .'/web/cache/',
'href="/engine/Shopware/Plugins/' => 'href="' . $cdn .'/engine/Shopware/Plugins/',
'src="/web/cache/' => 'src="' . $cdn .'/web/cache/',
'src="/engine/Shopware/Plugins/' => 'src="' . $cdn .'/engine/Shopware/Plugins/',
'src="/themes/' => 'src="' . $cdn .'/themes/',
'srcset="/themes/' => 'srcset="' . $cdn .'/themes/',
'content="/themes/' => 'content="' . $cdn .'/themes/'
]
]
]
];