-
Notifications
You must be signed in to change notification settings - Fork 19
SEO Url Support for E-Mail Templates #37
Copy link
Copy link
Open
Description
Please describe the feature you would like to see implemented.
Hey there,
great plugin. We've implemented something similar and we recently added support for SEO URLs within the mail template.
It's a great addition, if you want to link to products, categories, etc.
/**
* @throws StringTemplateRenderingException
*/
public function render(string $templateSource, array $data, Context $context): string
{
$name = \md5($templateSource);
$this->twig->setLoader(new ChainLoader([$this->platformTwig->getLoader(), new ArrayLoader([$name => $templateSource])]));
$this->twig->addGlobal('context', $context);
try {
$content = $this->twig->render($name, $data);
$request = $this->requestStack->getCurrentRequest();
if (!$request) {
return $content;
}
$host = $request->attributes->get(RequestTransformer::STOREFRONT_URL);
if (!$host) {
$host = $request->getSchemeAndHttpHost();
}
if (!$host) {
return $content;
}
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('domains.url', $host));
/** @var SalesChannelEntity $salesChannel */
$salesChannel = $this->salesChannelRepo->search($criteria, $context)->first();
if (!$salesChannel) {
return $content;
}
$salesChannelContext = $this->salesChannelContextFactory->create(Uuid::randomHex(), $salesChannel->getId());
return $this->seoUrlPlaceholderHandler->replace($content, $host, $salesChannelContext);
} catch (Error $error) {
throw new StringTemplateRenderingException($error->getMessage());
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels