Skip to content

Commit

Permalink
REL-12 HTML markup in Plain Text Templates
Browse files Browse the repository at this point in the history
- code formatting issues
  • Loading branch information
David Alger committed Jul 16, 2015
1 parent 57a09f4 commit 1ec5d16
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 60 deletions.
88 changes: 34 additions & 54 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Customer\Model\Customer as CustomerModel;
use Magento\Customer\Model\Metadata\Validator;
use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Framework\App\Area;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
use Magento\Framework\Event\ManagerInterface;
Expand All @@ -34,6 +35,7 @@
use Magento\Framework\Exception\State\InvalidTransitionException;
use Magento\Framework\ObjectFactory;
use Magento\Framework\Registry;
use Magento\Store\Model\ScopeInterface;
use Psr\Log\LoggerInterface as PsrLogger;
use Magento\Framework\Exception\MailException;
use Magento\Framework\Mail\Template\TransportBuilder;
Expand Down Expand Up @@ -567,20 +569,11 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU
{
try {
if ($this->isConfirmationRequired($customer)) {
$this->sendNewAccountEmail(
$customer,
self::NEW_ACCOUNT_EMAIL_CONFIRMATION,
$redirectUrl,
$customer->getStoreId()
);
$templateType = self::NEW_ACCOUNT_EMAIL_CONFIRMATION;
} else {
$this->sendNewAccountEmail(
$customer,
self::NEW_ACCOUNT_EMAIL_REGISTERED,
$redirectUrl,
$customer->getStoreId()
);
$templateType = self::NEW_ACCOUNT_EMAIL_REGISTERED;
}
$this->sendNewAccountEmail($customer, $templateType, $redirectUrl, $customer->getStoreId());
} catch (MailException $e) {
// If we are not able to send a new account email, this should be ignored
$this->logger->critical($e);
Expand Down Expand Up @@ -682,10 +675,11 @@ protected function createPasswordHash($password)
/**
* {@inheritdoc}
*/
public function validate(\Magento\Customer\Api\Data\CustomerInterface $customer)
public function validate(CustomerInterface $customer)
{
$customerErrors = $this->validator->validateData(
$this->extensibleDataObjectConverter->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface'),
$this->extensibleDataObjectConverter
->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface'),
[],
'customer'
);
Expand Down Expand Up @@ -852,27 +846,24 @@ protected function sendPasswordResetNotificationEmail($customer)
}

$customerEmailData = $this->getFullCustomerObject($customer);
/** @var \Magento\Framework\Mail\TransportInterface $transport */
$transport = $this->transportBuilder->setTemplateIdentifier(
$this->scopeConfig->getValue(
self::XML_PATH_RESET_PASSWORD_TEMPLATE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
)
)->setTemplateOptions(
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId]
)->setTemplateVars(
['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)]
)->setFrom(
$this->scopeConfig->getValue(

$templateId = $this->scopeConfig->getValue(
self::XML_PATH_RESET_PASSWORD_TEMPLATE,
ScopeInterface::SCOPE_STORE,
$storeId
);

$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
->setTemplateVars(['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)])
->setFrom($this->scopeConfig->getValue(
self::XML_PATH_FORGOT_EMAIL_IDENTITY,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$storeId
)
)->addTo(
$customer->getEmail(),
$this->customerViewHelper->getCustomerName($customer)
)->getTransport();
))
->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer))
->getTransport();

$transport->sendMessage();

return $this;
Expand Down Expand Up @@ -925,19 +916,14 @@ protected function getTemplateTypes()
*/
protected function sendEmailTemplate($customer, $template, $sender, $templateParams = [], $storeId = null)
{
/** @var \Magento\Framework\Mail\TransportInterface $transport */
$transport = $this->transportBuilder->setTemplateIdentifier(
$this->scopeConfig->getValue($template, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
)->setTemplateOptions(
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId]
)->setTemplateVars(
$templateParams
)->setFrom(
$this->scopeConfig->getValue($sender, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
)->addTo(
$customer->getEmail(),
$this->customerViewHelper->getCustomerName($customer)
)->getTransport();
$templateId = $this->scopeConfig->getValue($template, ScopeInterface::SCOPE_STORE, $storeId);
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
->setTemplateVars($templateParams)
->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))
->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer))
->getTransport();

$transport->sendMessage();

return $this;
Expand All @@ -956,11 +942,7 @@ protected function isConfirmationRequired($customer)
}
$storeId = $customer->getStoreId() ? $customer->getStoreId() : null;

return (bool)$this->scopeConfig->getValue(
self::XML_PATH_IS_CONFIRM,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
return (bool)$this->scopeConfig->getValue(self::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
Expand Down Expand Up @@ -1038,9 +1020,7 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
if (is_string($passwordLinkToken) && !empty($passwordLinkToken)) {
$customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
$customerSecure->setRpToken($passwordLinkToken);
$customerSecure->setRpTokenCreatedAt(
(new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)
);
$customerSecure->setRpTokenCreatedAt((new \DateTime())->format(DateTime::DATETIME_PHP_FORMAT));
$this->customerRepository->save($customer);
}
return true;
Expand Down
9 changes: 3 additions & 6 deletions app/code/Magento/Email/Model/AbstractTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
* @param \Magento\Framework\View\Asset\Repository $assetRepo
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param Template\Config $emailConfig
* @param \Magento\Email\Model\Template\Config $emailConfig
* @param \Magento\Email\Model\TemplateFactory $templateFactory
* @param \Magento\Framework\Url $urlModel
* @param array $data
Expand Down Expand Up @@ -236,11 +236,8 @@ protected function getTemplateInstance()
*/
public function loadByConfigPath($configPath)
{
$templateId = $this->scopeConfig->getValue(
$configPath,
ScopeInterface::SCOPE_STORE,
$this->getDesignConfig()->getStore()
);
$storeId = $this->getDesignConfig()->getStore();
$templateId = $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId);

if (is_numeric($templateId)) {
// Template was overridden in backend, so load template from database
Expand Down

0 comments on commit 1ec5d16

Please sign in to comment.