Skip to content

Commit 9fc059b

Browse files
committed
MDVA-275: Emails from admin being sent out using default config’s email, not the specific store email
1 parent 88bfa91 commit 9fc059b

File tree

7 files changed

+40
-5
lines changed

7 files changed

+40
-5
lines changed

app/code/Magento/Checkout/Helper/Data.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'one
304304
'items' => nl2br($items),
305305
'total' => $total,
306306
]
307+
)->setScopeId(
308+
$checkout->getStoreId()
307309
)->setFrom(
308310
$this->scopeConfig->getValue(
309311
'checkout/payment_failed/identity',

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ protected function sendEmailTemplate($customer, $template, $sender, $templatePar
920920
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
921921
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
922922
->setTemplateVars($templateParams)
923+
->setScopeId($storeId)
923924
->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))
924925
->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer))
925926
->getTransport();

app/code/Magento/Customer/Model/Customer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,8 @@ protected function _sendEmailTemplate($template, $sender, $templateParams = [],
828828
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId]
829829
)->setTemplateVars(
830830
$templateParams
831+
)->setScopeId(
832+
$storeId
831833
)->setFrom(
832834
$this->_scopeConfig->getValue($sender, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
833835
)->addTo(

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ public function sendConfirmationRequestEmail()
654654

655655
$this->inlineTranslation->suspend();
656656

657+
$storeId = $this->_storeManager->getStore()->getId();
657658
$this->_transportBuilder->setTemplateIdentifier(
658659
$this->_scopeConfig->getValue(
659660
self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
@@ -662,10 +663,12 @@ public function sendConfirmationRequestEmail()
662663
)->setTemplateOptions(
663664
[
664665
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
665-
'store' => $this->_storeManager->getStore()->getId(),
666+
'store' => $storeId,
666667
]
667668
)->setTemplateVars(
668669
['subscriber' => $this, 'store' => $this->_storeManager->getStore()]
670+
)->setScopeId(
671+
$storeId
669672
)->setFrom(
670673
$this->_scopeConfig->getValue(
671674
self::XML_PATH_CONFIRM_EMAIL_IDENTITY,
@@ -707,6 +710,7 @@ public function sendConfirmationSuccessEmail()
707710

708711
$this->inlineTranslation->suspend();
709712

713+
$storeId = $this->_storeManager->getStore()->getId();
710714
$this->_transportBuilder->setTemplateIdentifier(
711715
$this->_scopeConfig->getValue(
712716
self::XML_PATH_SUCCESS_EMAIL_TEMPLATE,
@@ -715,10 +719,12 @@ public function sendConfirmationSuccessEmail()
715719
)->setTemplateOptions(
716720
[
717721
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
718-
'store' => $this->_storeManager->getStore()->getId(),
722+
'store' => $storeId,
719723
]
720724
)->setTemplateVars(
721725
['subscriber' => $this]
726+
)->setScopeId(
727+
$storeId
722728
)->setFrom(
723729
$this->_scopeConfig->getValue(
724730
self::XML_PATH_SUCCESS_EMAIL_IDENTITY,
@@ -759,6 +765,7 @@ public function sendUnsubscriptionEmail()
759765

760766
$this->inlineTranslation->suspend();
761767

768+
$storeId = $this->_storeManager->getStore()->getId();
762769
$this->_transportBuilder->setTemplateIdentifier(
763770
$this->_scopeConfig->getValue(
764771
self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE,
@@ -767,10 +774,12 @@ public function sendUnsubscriptionEmail()
767774
)->setTemplateOptions(
768775
[
769776
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
770-
'store' => $this->_storeManager->getStore()->getId(),
777+
'store' => $storeId,
771778
]
772779
)->setTemplateVars(
773780
['subscriber' => $this]
781+
)->setScopeId(
782+
$storeId
774783
)->setFrom(
775784
$this->_scopeConfig->getValue(
776785
self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY,

app/code/Magento/ProductAlert/Model/Email.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ public function send()
374374
'customerName' => $this->_customerHelper->getCustomerName($this->_customer),
375375
'alertGrid' => $alertGrid,
376376
]
377+
)->setScopeId(
378+
$storeId
377379
)->setFrom(
378380
$this->_scopeConfig->getValue(
379381
self::XML_PATH_EMAIL_IDENTITY,

app/code/Magento/Wishlist/Controller/Index/Send.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public function execute()
186186

187187
try {
188188
foreach ($emails as $email) {
189+
$storeId = $this->storeManager->getStore()->getStoreId();
189190
$transport = $this->_transportBuilder->setTemplateIdentifier(
190191
$this->scopeConfig->getValue(
191192
'wishlist/email/email_template',
@@ -194,7 +195,7 @@ public function execute()
194195
)->setTemplateOptions(
195196
[
196197
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
197-
'store' => $this->storeManager->getStore()->getStoreId(),
198+
'store' => $storeId,
198199
]
199200
)->setTemplateVars(
200201
[
@@ -206,6 +207,8 @@ public function execute()
206207
'message' => $message,
207208
'store' => $this->storeManager->getStore(),
208209
]
210+
)->setScopeId(
211+
$storeId
209212
)->setFrom(
210213
$this->scopeConfig->getValue(
211214
'wishlist/email/email_identity',

lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class TransportBuilder
8484
*/
8585
protected $mailTransportFactory;
8686

87+
/** @var int|null */
88+
private $scopeId;
89+
8790
/**
8891
* @param FactoryInterface $templateFactory
8992
* @param MessageInterface $message
@@ -156,6 +159,18 @@ public function setReplyTo($email, $name = null)
156159
return $this;
157160
}
158161

162+
/**
163+
* Set scope
164+
*
165+
* @param int $scopeId
166+
* @return $this
167+
*/
168+
public function setScopeId($scopeId)
169+
{
170+
$this->scopeId = $scopeId;
171+
return $this;
172+
}
173+
159174
/**
160175
* Set mail from address
161176
*
@@ -164,7 +179,7 @@ public function setReplyTo($email, $name = null)
164179
*/
165180
public function setFrom($from)
166181
{
167-
$result = $this->_senderResolver->resolve($from);
182+
$result = $this->_senderResolver->resolve($from, $this->scopeId);
168183
$this->message->setFrom($result['email'], $result['name']);
169184
return $this;
170185
}
@@ -242,6 +257,7 @@ protected function reset()
242257
$this->templateIdentifier = null;
243258
$this->templateVars = null;
244259
$this->templateOptions = null;
260+
$this->scopeId = null;
245261
return $this;
246262
}
247263

0 commit comments

Comments
 (0)