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

Fixes magento#13120
  • Loading branch information
Anton Evers committed Jan 14, 2018
1 parent 2ad32d9 commit 68c3223
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 2 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 @@ -305,6 +305,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/Checkout/Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public function testSendPaymentFailedEmail()
$this->returnSelf()
);

$this->_transportBuilder->expects($this->once())->method('setScopeId')->will($this->returnSelf());
$this->_transportBuilder->expects($this->once())->method('addBcc')->will($this->returnSelf());
$this->_transportBuilder->expects(
$this->once()
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 @@ -1143,6 +1143,7 @@ protected function sendEmailTemplate(
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
->setTemplateVars($templateParams)
->setScopeId($storeId)
->setFrom($this->scopeConfig->getValue(
$sender,
ScopeInterface::SCOPE_STORE,
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 @@ -831,6 +831,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, ScopeInterface::SCOPE_STORE, $storeId)
)->addTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,9 @@ public function testSendPasswordReminderEmail()
->method('setTemplateVars')
->with(['customer' => $this->customerSecure, 'store' => $this->store])
->willReturnSelf();
$this->transportBuilder->expects($this->once())
->method('setScopeId')
->willReturnSelf();
$this->transportBuilder->expects($this->once())
->method('setFrom')
->with($sender)
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public function testSendNewAccountEmailWithoutStoreId()
'setTemplateIdentifier',
'setTemplateOptions',
'setTemplateVars',
'setScopeId',
'setFrom',
'addTo',
];
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Newsletter/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ public function sendConfirmationRequestEmail()
]
)->setTemplateVars(
['subscriber' => $this, 'store' => $this->_storeManager->getStore()]
)->setScopeId(
$this->_storeManager->getStore()->getId()
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_CONFIRM_EMAIL_IDENTITY,
Expand Down Expand Up @@ -730,6 +732,8 @@ public function sendConfirmationSuccessEmail()
]
)->setTemplateVars(
['subscriber' => $this]
)->setScopeId(
$this->_storeManager->getStore()->getId()
)->setFrom(
$this->_scopeConfig->getValue(
self::XML_PATH_SUCCESS_EMAIL_IDENTITY,
Expand Down Expand Up @@ -782,6 +786,8 @@ public function sendUnsubscriptionEmail()
]
)->setTemplateVars(
['subscriber' => $this]
)->setScopeId(
$this->_storeManager->getStore()->getId()
)->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 @@ -377,6 +377,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
2 changes: 2 additions & 0 deletions app/code/Magento/Wishlist/Controller/Index/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public function execute()
'message' => $message,
'store' => $this->storeManager->getStore(),
]
)->setScopeId(
$this->storeManager->getStore()->getStoreId()
)->setFrom(
$this->scopeConfig->getValue(
'wishlist/email/email_identity',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public function testExecute()
['wishlist/email/email_identity', ScopeInterface::SCOPE_STORE, null, $from],
]);

$this->store->expects($this->once())
$this->store->expects($this->exactly(2))
->method('getStoreId')
->willReturn($storeId);

Expand Down Expand Up @@ -663,6 +663,9 @@ public function testExecute()
'store' => $this->store,
])
->willReturnSelf();
$this->transportBuilder->expects($this->once())
->method('setScopeId')
->willReturnSelf();
$this->transportBuilder->expects($this->once())
->method('setFrom')
->with($from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class TransportBuilder
*/
protected $mailTransportFactory;

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

/**
* @param FactoryInterface $templateFactory
* @param MessageInterface $message
Expand Down Expand Up @@ -160,6 +163,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 @@ -168,7 +183,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 @@ -246,6 +261,7 @@ protected function reset()
$this->templateIdentifier = null;
$this->templateVars = null;
$this->templateOptions = null;
$this->scopeId = null;
return $this;
}

Expand Down

0 comments on commit 68c3223

Please sign in to comment.