Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert removed templates for mail dynamic contents, order mails mainly, create MailPartialTemplateRenderer to manage this feature #14601

Merged
merged 4 commits into from Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -133,6 +133,7 @@ php-cs-fixer
translations/*
mails/*
!mails/themes/
!mails/_partials/
themes/default-bootstrap/lang/*
themes/default-bootstrap/modules/*/translations/*.php
themes/default-bootstrap/mails/*
Expand Down
18 changes: 3 additions & 15 deletions classes/PaymentModule.php
Expand Up @@ -24,6 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Adapter\StockManager;
use PrestaShop\PrestaShop\Adapter\MailTemplate\MailPartialTemplateRenderer;

abstract class PaymentModuleCore extends Module
{
Expand Down Expand Up @@ -895,22 +896,9 @@ protected function getEmailTemplateContent($template_name, $mail_type, $var)
return '';
}

$pathToFindEmail = array(
_PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name,
_PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . $template_name,
_PS_MAIL_DIR_ . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name,
_PS_MAIL_DIR_ . 'en' . DIRECTORY_SEPARATOR . $template_name,
);
$partialRenderer = new MailPartialTemplateRenderer($this->context);
jolelievre marked this conversation as resolved.
Show resolved Hide resolved

foreach ($pathToFindEmail as $path) {
if (Tools::file_exists_cache($path)) {
$this->context->smarty->assign('list', $var);

return $this->context->smarty->fetch($path);
}
}

return '';
return $partialRenderer->render($template_name, $var);
}

protected function createOrderFromCart(
Expand Down
54 changes: 54 additions & 0 deletions mails/_partials/order_conf_cart_rules.tpl
@@ -0,0 +1,54 @@
{**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{foreach $list as $cart_rule}
<tr class="conf_body">
<td bgcolor="#f8f8f8" colspan="4" style="border:1px solid #D6D4D4;color:#333;padding:7px 0">
<table class="table" style="width:100%;border-collapse:collapse">
<tr>
<td width="5" style="color:#333;padding:0"></td>
<td align="right" style="color:#333;padding:0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<strong>{$cart_rule['voucher_name']}</strong>
</font>
</td>
<td width="5" style="color:#333;padding:0"></td>
</tr>
</table>
</td>
<td bgcolor="#f8f8f8" colspan="4" style="border:1px solid #D6D4D4;color:#333;padding:7px 0">
<table class="table" style="width:100%;border-collapse:collapse">
<tr>
<td width="5" style="color:#333;padding:0"></td>
<td align="right" style="color:#333;padding:0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
{$cart_rule['voucher_reduction']}
</font>
</td>
<td width="5" style="color:#333;padding:0"></td>
</tr>
</table>
</td>
</tr>
{/foreach}
3 changes: 3 additions & 0 deletions mails/_partials/order_conf_cart_rules.txt
@@ -0,0 +1,3 @@
{foreach $list as $cart_rule}
{$cart_rule['voucher_name']} {$cart_rule['voucher_reduction']}
{/foreach}
136 changes: 136 additions & 0 deletions mails/_partials/order_conf_product_list.tpl
@@ -0,0 +1,136 @@
{**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{foreach $list as $product}
<tr>
<td style="border:1px solid #D6D4D4;">
<table class="table">
<tr>
<td width="5">&nbsp;</td>
<td>
<font size="2" face="Open-sans, sans-serif" color="#555454">
{$product['reference']}
</font>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td>
<td style="border:1px solid #D6D4D4;">
<table class="table">
<tr>
<td width="5">&nbsp;</td>
<td>
<font size="2" face="Open-sans, sans-serif" color="#555454">
<strong>{$product['name']}</strong>
{if count($product['customization']) == 1}
<br>
{foreach $product['customization'] as $customization}
{$customization['customization_text']}
{/foreach}
{/if}

{hook h='displayProductPriceBlock' product=$product type="unit_price"}
</font>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td>
<td style="border:1px solid #D6D4D4;">
<table class="table">
<tr>
<td width="5">&nbsp;</td>
<td align="right">
<font size="2" face="Open-sans, sans-serif" color="#555454">
{$product['unit_price']}
</font>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td>
<td style="border:1px solid #D6D4D4;">
<table class="table">
<tr>
<td width="5">&nbsp;</td>
<td align="right">
<font size="2" face="Open-sans, sans-serif" color="#555454">
{$product['quantity']}
</font>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td>
<td style="border:1px solid #D6D4D4;">
<table class="table">
<tr>
<td width="5">&nbsp;</td>
<td align="right">
<font size="2" face="Open-sans, sans-serif" color="#555454">
{$product['price']}
</font>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td>
</tr>
{if count($product['customization']) > 1}
{foreach $product['customization'] as $customization}
<tr>
<td colspan="3" style="border:1px solid #D6D4D4;">
<table class="table">
<tr>
<td width="5">&nbsp;</td>
<td>
<font size="2" face="Open-sans, sans-serif" color="#555454">
{$customization['customization_text']}
</font>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td>
<td style="border:1px solid #D6D4D4;">
<table class="table">
<tr>
<td width="5">&nbsp;</td>
<td align="right">
<font size="2" face="Open-sans, sans-serif" color="#555454">
{if count($product['customization']) > 1}
{$customization['customization_quantity']}
jolelievre marked this conversation as resolved.
Show resolved Hide resolved
{/if}
</font>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td>
<td style="border:1px solid #D6D4D4;"></td>
</tr>
{/foreach}
{/if}
{/foreach}
20 changes: 20 additions & 0 deletions mails/_partials/order_conf_product_list.txt
@@ -0,0 +1,20 @@
{foreach $list as $product}
{$product['reference']}
jolelievre marked this conversation as resolved.
Show resolved Hide resolved

{$product['name']}

{$product['price']}
{capture "productPriceBlock"}{hook h='displayProductPriceBlock' product=$product type="unit_price"}{/capture}{$smarty.capture.productPriceBlock|strip_tags|trim}

{$product['quantity']}

{$product['price']}

{foreach $product['customization'] as $customization}
{$customization['customization_text']}

{if count($product['customization']) > 1}
{$customization['customization_quantity']}
{/if}
{/foreach}
{/foreach}
79 changes: 79 additions & 0 deletions src/Adapter/MailTemplate/MailPartialTemplateRenderer.php
@@ -0,0 +1,79 @@
<?php
/**
* 2007-2019 PrestaShop SA and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShop\PrestaShop\Adapter\MailTemplate;

use Context as LegacyContext;
use Tools;

/**
* Class MailPartialTemplateRenderer renders partial mail templates (especially for order). This
* feature was moved in this service so that it can be shared between PaymentModule and MailPreviewVariablesBuilder.
*/
class MailPartialTemplateRenderer
{
/** @var LegacyContext */
private $context;

/**
* @param LegacyContext $context
*/
public function __construct(LegacyContext $context)
{
$this->context = $context;
}

/**
* Fetch the content of $partialTemplateName inside the folder
* current_theme/mails/current_iso_lang/ if found, otherwise in
* mails/current_iso_lang.
*
* @param string $partialTemplateName template name with extension
* @param array $variables sent to smarty as 'list'
*
* @return string
*/
public function render($partialTemplateName, array $variables)
jolelievre marked this conversation as resolved.
Show resolved Hide resolved
{
$potentialPaths = array(
_PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $partialTemplateName,
_PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . $partialTemplateName,
_PS_MAIL_DIR_ . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $partialTemplateName,
_PS_MAIL_DIR_ . 'en' . DIRECTORY_SEPARATOR . $partialTemplateName,
_PS_MAIL_DIR_ . '_partials' . DIRECTORY_SEPARATOR . $partialTemplateName,
);

foreach ($potentialPaths as $path) {
if (Tools::file_exists_cache($path)) {
$this->context->smarty->assign('list', $variables);

return $this->context->smarty->fetch($path);
}
}

return '';
}
}