Skip to content

Commit

Permalink
MDVA-275: Emails from admin being sent out using default config’s ema…
Browse files Browse the repository at this point in the history
…il, not the specific store email
  • Loading branch information
isitnikov committed May 17, 2016
1 parent 88bfa91 commit 9fc059b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/code/Magento/Checkout/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'one
'items' => nl2br($items),
'total' => $total,
]
)->setScopeId(
$checkout->getStoreId()
)->setFrom(
$this->scopeConfig->getValue(
'checkout/payment_failed/identity',
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ protected function sendEmailTemplate($customer, $template, $sender, $templatePar
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
->setTemplateVars($templateParams)
->setScopeId($storeId)
->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))
->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer))
->getTransport();
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ protected function _sendEmailTemplate($template, $sender, $templateParams = [],
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId]
)->setTemplateVars(
$templateParams
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue($sender, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
)->addTo(
Expand Down
15 changes: 12 additions & 3 deletions app/code/Magento/Newsletter/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ public function sendConfirmationRequestEmail()

$this->inlineTranslation->suspend();

$storeId = $this->_storeManager->getStore()->getId();
$this->_transportBuilder->setTemplateIdentifier(
$this->_scopeConfig->getValue(
self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
Expand All @@ -662,10 +663,12 @@ public function sendConfirmationRequestEmail()
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->_storeManager->getStore()->getId(),
'store' => $storeId,
]
)->setTemplateVars(
['subscriber' => $this, 'store' => $this->_storeManager->getStore()]
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_CONFIRM_EMAIL_IDENTITY,
Expand Down Expand Up @@ -707,6 +710,7 @@ public function sendConfirmationSuccessEmail()

$this->inlineTranslation->suspend();

$storeId = $this->_storeManager->getStore()->getId();
$this->_transportBuilder->setTemplateIdentifier(
$this->_scopeConfig->getValue(
self::XML_PATH_SUCCESS_EMAIL_TEMPLATE,
Expand All @@ -715,10 +719,12 @@ public function sendConfirmationSuccessEmail()
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->_storeManager->getStore()->getId(),
'store' => $storeId,
]
)->setTemplateVars(
['subscriber' => $this]
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_SUCCESS_EMAIL_IDENTITY,
Expand Down Expand Up @@ -759,6 +765,7 @@ public function sendUnsubscriptionEmail()

$this->inlineTranslation->suspend();

$storeId = $this->_storeManager->getStore()->getId();
$this->_transportBuilder->setTemplateIdentifier(
$this->_scopeConfig->getValue(
self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE,
Expand All @@ -767,10 +774,12 @@ public function sendUnsubscriptionEmail()
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->_storeManager->getStore()->getId(),
'store' => $storeId,
]
)->setTemplateVars(
['subscriber' => $this]
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY,
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/ProductAlert/Model/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ public function send()
'customerName' => $this->_customerHelper->getCustomerName($this->_customer),
'alertGrid' => $alertGrid,
]
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_EMAIL_IDENTITY,
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Wishlist/Controller/Index/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public function execute()

try {
foreach ($emails as $email) {
$storeId = $this->storeManager->getStore()->getStoreId();
$transport = $this->_transportBuilder->setTemplateIdentifier(
$this->scopeConfig->getValue(
'wishlist/email/email_template',
Expand All @@ -194,7 +195,7 @@ public function execute()
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getStoreId(),
'store' => $storeId,
]
)->setTemplateVars(
[
Expand All @@ -206,6 +207,8 @@ public function execute()
'message' => $message,
'store' => $this->storeManager->getStore(),
]
)->setScopeId(
$storeId
)->setFrom(
$this->scopeConfig->getValue(
'wishlist/email/email_identity',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class TransportBuilder
*/
protected $mailTransportFactory;

/** @var int|null */
private $scopeId;

/**
* @param FactoryInterface $templateFactory
* @param MessageInterface $message
Expand Down Expand Up @@ -156,6 +159,18 @@ public function setReplyTo($email, $name = null)
return $this;
}

/**
* Set scope
*
* @param int $scopeId
* @return $this
*/
public function setScopeId($scopeId)
{
$this->scopeId = $scopeId;
return $this;
}

/**
* Set mail from address
*
Expand All @@ -164,7 +179,7 @@ public function setReplyTo($email, $name = null)
*/
public function setFrom($from)
{
$result = $this->_senderResolver->resolve($from);
$result = $this->_senderResolver->resolve($from, $this->scopeId);
$this->message->setFrom($result['email'], $result['name']);
return $this;
}
Expand Down Expand Up @@ -242,6 +257,7 @@ protected function reset()
$this->templateIdentifier = null;
$this->templateVars = null;
$this->templateOptions = null;
$this->scopeId = null;
return $this;
}

Expand Down

0 comments on commit 9fc059b

Please sign in to comment.