64 private $designConfig;
71 private $isChildTemplate =
false;
78 private $templateFilter;
85 private $emulatedDesignConfig =
false;
108 private $hasDesignBeenApplied =
false;
195 \
Magento\Framework\UrlInterface $urlModel,
199 $this->area = isset(
$data[
'area']) ?
$data[
'area'] :
null;
200 $this->store = isset(
$data[
'store']) ?
$data[
'store'] :
null;
209 $this->urlModel = $urlModel;
226 ->loadByConfigPath($configPath, $variables)
227 ->setTemplateType($this->
getType())
228 ->setIsChildTemplate(
true);
232 $templateText = $this->filterManager->stripTags(
$template->getTemplateText());
233 $template->setTemplateText(trim($templateText));
236 $processedTemplate =
$template->getProcessedTemplate($variables);
238 $processedTemplate = trim($processedTemplate);
241 return $processedTemplate;
251 return $this->templateFactory->create();
282 $templateFile = $this->emailConfig->getTemplateFilename(
$templateId, $designParams);
285 $this->setTemplateType($templateTypeCode);
293 if (preg_match(
'/^<!--[\w\W]+?-->/m', $templateText, $matches) && strpos($matches[0],
'Copyright') !==
false) {
294 $templateText = str_replace($matches[0],
'', $templateText);
297 if (preg_match(
'/<!--@subject\s*(.*?)\s*@-->/u', $templateText, $matches)) {
298 $this->setTemplateSubject($matches[1]);
299 $templateText = str_replace($matches[0],
'', $templateText);
302 if (preg_match(
'/<!--@vars\s*((?:.)*?)\s*@-->/us', $templateText, $matches)) {
303 $this->
setData(
'orig_template_variables', str_replace(
"\n",
'', $matches[1]));
304 $templateText = str_replace($matches[0],
'', $templateText);
307 if (preg_match(
'/<!--@styles\s*(.*?)\s*@-->/s', $templateText, $matches)) {
308 $this->setTemplateStyles($matches[1]);
309 $templateText = str_replace($matches[0],
'', $templateText);
313 $templateText = trim(preg_replace(
'#\{\*.*\*\}#suU',
'', $templateText));
315 $this->setTemplateText($templateText);
331 ->setUseSessionInUrl(
false)
332 ->setPlainTemplateMode($this->
isPlain())
334 ->setTemplateProcessor([$this,
'getTemplateContent']);
336 $variables[
'this'] = $this;
343 if (isset($variables[
'subscriber'])) {
344 $storeId = $variables[
'subscriber']->getStoreId();
356 }
catch (\Exception $e) {
358 throw new \LogicException(
__($e->getMessage()), $e->getCode(), $e);
360 if ($isDesignApplied) {
374 return $this->assetRepo->getUrlWithParams(
375 self::DEFAULT_LOGO_FILE_ID,
388 $store = $this->storeManager->getStore($store);
389 $fileName = $this->scopeConfig->getValue(
390 self::XML_PATH_DESIGN_EMAIL_LOGO,
398 return $this->storeManager->getStore()->getBaseUrl(
399 \
Magento\Framework\UrlInterface::URL_TYPE_MEDIA
414 $store = $this->storeManager->getStore($store);
415 $alt = $this->scopeConfig->getValue(
416 self::XML_PATH_DESIGN_EMAIL_LOGO_ALT,
423 return $store->getFrontendName();
438 $store = $this->storeManager->getStore(
$storeId);
439 if (!isset($variables[
'store'])) {
440 $variables[
'store'] = $store;
442 if (!isset($variables[
'logo_url'])) {
445 if (!isset($variables[
'logo_alt'])) {
448 if (!isset($variables[
'logo_width'])) {
449 $variables[
'logo_width'] = $this->scopeConfig->getValue(
450 self::XML_PATH_DESIGN_EMAIL_LOGO_WIDTH,
455 if (!isset($variables[
'logo_height'])) {
456 $variables[
'logo_height'] = $this->scopeConfig->getValue(
457 self::XML_PATH_DESIGN_EMAIL_LOGO_HEIGHT,
462 if (!isset($variables[
'store_phone'])) {
463 $variables[
'store_phone'] = $this->scopeConfig->getValue(
464 StoreInformation::XML_PATH_STORE_INFO_PHONE,
469 if (!isset($variables[
'store_hours'])) {
470 $variables[
'store_hours'] = $this->scopeConfig->getValue(
471 StoreInformation::XML_PATH_STORE_INFO_HOURS,
476 if (!isset($variables[
'store_email'])) {
477 $variables[
'store_email'] = $this->scopeConfig->getValue(
478 'trans_email/ident_support/email',
484 if (!$this->
isPlain() && !isset($variables[
'template_styles'])) {
485 $variables[
'template_styles'] = $this->getTemplateStyles();
504 $this->hasDesignBeenApplied =
true;
507 $storeId = $designConfig->getStore();
508 $area = $designConfig->getArea();
512 $this->appEmulation->startEnvironmentEmulation(
$storeId, $area,
true);
524 $this->appEmulation->stopEnvironmentEmulation();
525 $this->hasDesignBeenApplied =
false;
537 if ($this->area ===
null) {
538 $this->area = $this->emailConfig->getTemplateArea(
$templateId);
555 $area = $this->emailConfig->getTemplateArea(
$templateId);
556 $this->design->setDesignTheme(
$theme, $area);
571 'theme' => $this->design->getDesignTheme()->getCode(),
572 'themeModel' => $this->design->getDesignTheme(),
573 'locale' => $this->design->getLocale(),
584 if ($this->designConfig ===
null) {
585 if ($this->area ===
null) {
586 $this->area = $this->design->getArea();
588 if ($this->store ===
null) {
589 $this->store = $this->storeManager->getStore()->getId();
592 [
'area' => $this->area,
'store' => $this->store]
595 return $this->designConfig;
609 __(
'The design config needs an area and a store. Verify that both are set and try again.')
623 return $this->isChildTemplate;
646 $this->templateFilter = $filter;
657 if (empty($this->templateFilter)) {
659 $this->templateFilter->setUseAbsoluteLinks($this->getUseAbsoluteLinks())
661 ->setUrlModel($this->urlModel);
663 return $this->templateFilter;
686 $this->emulatedDesignConfig =
false;
697 if ($this->emulatedDesignConfig) {
700 $this->emulatedDesignConfig =
false;
726 abstract public function getType();
739 if ($this->storeManager->getStore()->getId() !=
$store->getId()) {
740 $params[
'_scope_to_url'] =
true;
const XML_PATH_DESIGN_EMAIL_LOGO_ALT
setData($key, $value=null)
setForcedTheme($templateId, $theme)
setTemplateFilter(Template\Filter $filter)
const XML_PATH_DESIGN_EMAIL_LOGO_WIDTH
load($modelId, $field=null)
setIsChildTemplate($isChildTemplate)
const XML_PATH_DESIGN_EMAIL_LOGO
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Registry $registry, \Magento\Store\Model\App\Emulation $appEmulation, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Email\Model\Template\Config $emailConfig, \Magento\Email\Model\TemplateFactory $templateFactory, \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\UrlInterface $urlModel, array $data=[])
setDesignConfig(array $config)
getProcessedTemplate(array $variables=[])
const DEFAULT_LOGO_FILE_ID
const DEFAULT_DESIGN_AREA
setForcedArea($templateId)
emulateDesign($storeId, $area=self::DEFAULT_DESIGN_AREA)
loadByConfigPath($configPath)
getUrl(Store $store, $route='', $params=[])
const XML_PATH_DESIGN_EMAIL_LOGO_HEIGHT
getTemplateContent($configPath, array $variables)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
addEmailVariables($variables, $storeId)