From 749f0e642e15a546d38142a1192211adcaf929ac Mon Sep 17 00:00:00 2001 From: Benjamin Volle Date: Tue, 10 Oct 2017 17:18:07 +0200 Subject: [PATCH] Fix for wrong sender when sending sales emails from BO for non-default stores --- .../Sales/Model/Order/Email/SenderBuilder.php | 2 ++ .../Mail/Template/TransportBuilder.php | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php b/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php index b6703fbee87f5..2328afcd4da2d 100644 --- a/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php +++ b/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php @@ -48,6 +48,8 @@ public function __construct( */ public function send() { + $this->transportBuilder->setScopeId($this->identityContainer->getStore()->getId()); + $this->configureEmailTemplate(); $this->transportBuilder->addTo( diff --git a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php index 5b90753605a49..53cef60f50aed 100644 --- a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php +++ b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php @@ -84,6 +84,11 @@ class TransportBuilder */ protected $mailTransportFactory; + /** + * @var int|null + */ + protected $scopeId; + /** * @param FactoryInterface $templateFactory * @param MessageInterface $message @@ -164,11 +169,23 @@ 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; } + /** + * Set scope + * + * @param int $scopeId + * @return $this + */ + public function setScopeId($scopeId) + { + $this->scopeId = $scopeId; + return $this; + } + /** * Set template identifier * @@ -242,6 +259,7 @@ protected function reset() $this->templateIdentifier = null; $this->templateVars = null; $this->templateOptions = null; + $this->scopeId = null; return $this; }