-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Please describe the feature you would like to see implemented.
The Idea is to allow Plugins to extend existing E-Mail Templates so that they can add Information aswell.
In My Setup i have an E-Mail Template defined in the Theme, another Plugin adds some Custom Fields to the order and should add this data to the e-mail as well.
It kind ofworks when using the e-mail-test function in the administation by extending the corresponding blocks like here:
#34 (comment)
the only thing that the extension has to do is to register the email path in its main/installation file like so:
Example-File: MyPlugin/src/MyPlugin.php
public function getViewPaths(): array
{
$viewPaths = parent::getViewPaths();
$viewPaths[] = 'Resources/views/storefront';
$viewPaths[] = 'Resources/views/email';
return $viewPaths;
}
The Paths of this Plugin (FroshPlatformTemplateMail) does not support this completely, in my situation i looked into the Code of the plugin and found out, that the path of the additional Plugin is found but not used, but i am not 100% sure if this fix will be enough in all constellations, as the order of plugin intallation might be important here. I added this code $paths = array_reverse($paths); into the file: FroshPlatformTemplateMail/src/Services/MailFinderService.php so it looks like this:
...
if (\is_string($themePath)) {
usort($paths, static function ($a, $b) use ($themePath) {
if (str_contains($a, $themePath)) {
return -1;
}
if (str_contains($b, $themePath)) {
return 1;
}
return 0;
});
}
$paths = array_reverse($paths);
foreach ($paths as $path) {
foreach ($this->availableLoaders as $availableLoader) {
$supportedExtensions = $availableLoader->supportedExtensions();
foreach ($supportedExtensions as $supportedExtension) {
foreach ($searchFolder as $folder) {
$filePath = $path . '/email/' . $folder . '/' . $technicalName . '/' . $type . $supportedExtension;
if (file_exists($filePath) && $content = $availableLoader->load($filePath)) {
return $returnFolder ? $filePath : $content;
}
}
}
}
}
...
Now my Plugin is loaded before the Theme and thus i can replace some parts in the file, as long as there are blocks defined in the mail-template.
Caveats:
While debugging the $paths-variable i could see that this function is called multiple times when causing an actions that requires the mail templates. The order of items changed between executions (still in the same process), so it could very well be that it does not work in all cases, as the order might be changed due to a different order of plugin installations.