From c716aec033020b86a15b9ac71df2746bcac953a8 Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Thu, 11 Jan 2018 16:04:07 +0600 Subject: [PATCH] =?UTF-8?q?MDVA-275:=20Emails=20from=20admin=20being=20sen?= =?UTF-8?q?t=20out=20using=20default=20config=E2=80=99s=20email,=20not=20t?= =?UTF-8?q?he=20specific=20store=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #13120 --- app/code/Magento/Checkout/Helper/Data.php | 2 ++ .../Checkout/Test/Unit/Helper/DataTest.php | 1 + .../Customer/Model/AccountManagement.php | 2 +- app/code/Magento/Customer/Model/Customer.php | 2 ++ .../Test/Unit/Model/AccountManagementTest.php | 3 +++ .../Customer/Test/Unit/Model/CustomerTest.php | 1 + .../Magento/Newsletter/Model/Subscriber.php | 6 ++++++ app/code/Magento/ProductAlert/Model/Email.php | 2 ++ .../Magento/Wishlist/Controller/Index/Send.php | 2 ++ .../Test/Unit/Controller/Index/SendTest.php | 5 ++++- .../Mail/Template/TransportBuilder.php | 18 +++++++++++++++++- 11 files changed, 41 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Checkout/Helper/Data.php b/app/code/Magento/Checkout/Helper/Data.php index b3c2e17e5d678..ba7179464641e 100644 --- a/app/code/Magento/Checkout/Helper/Data.php +++ b/app/code/Magento/Checkout/Helper/Data.php @@ -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', diff --git a/app/code/Magento/Checkout/Test/Unit/Helper/DataTest.php b/app/code/Magento/Checkout/Test/Unit/Helper/DataTest.php index 31203b63f854a..456f0a8b5efc3 100644 --- a/app/code/Magento/Checkout/Test/Unit/Helper/DataTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Helper/DataTest.php @@ -212,6 +212,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() diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 8ba44f86f5a0e..6bf9809f078de 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -1148,7 +1148,7 @@ protected function sendEmailTemplate( $transport = $this->transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions( ['area' => Area::AREA_FRONTEND, 'store' => $storeId] - )->setTemplateVars($templateParams)->setFrom( + )->setTemplateVars($templateParams)->setScopeId($storeId)->setFrom( $this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId) )->addTo($email, $this->customerViewHelper->getCustomerName($customer))->getTransport(); diff --git a/app/code/Magento/Customer/Model/Customer.php b/app/code/Magento/Customer/Model/Customer.php index e0a7281776de9..8d1c4610aedfd 100644 --- a/app/code/Magento/Customer/Model/Customer.php +++ b/app/code/Magento/Customer/Model/Customer.php @@ -839,6 +839,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( diff --git a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php index d72d7ec87ec3d..fcdfa1493e4ec 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php @@ -990,6 +990,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) diff --git a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php index f5b7f08d2906d..3941e9831d3c9 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php @@ -169,6 +169,7 @@ public function testSendNewAccountEmailWithoutStoreId() 'setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars', + 'setScopeId', 'setFrom', 'addTo', ]; diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index b8d7ccf83af7c..f3b2234380a9e 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -689,6 +689,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, @@ -742,6 +744,8 @@ public function sendConfirmationSuccessEmail() ] )->setTemplateVars( ['subscriber' => $this] + )->setScopeId( + $this->_storeManager->getStore()->getId() )->setFrom( $this->_scopeConfig->getValue( self::XML_PATH_SUCCESS_EMAIL_IDENTITY, @@ -794,6 +798,8 @@ public function sendUnsubscriptionEmail() ] )->setTemplateVars( ['subscriber' => $this] + )->setScopeId( + $this->_storeManager->getStore()->getId() )->setFrom( $this->_scopeConfig->getValue( self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY, diff --git a/app/code/Magento/ProductAlert/Model/Email.php b/app/code/Magento/ProductAlert/Model/Email.php index 7bc4aba351546..1c5588655a12b 100644 --- a/app/code/Magento/ProductAlert/Model/Email.php +++ b/app/code/Magento/ProductAlert/Model/Email.php @@ -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, diff --git a/app/code/Magento/Wishlist/Controller/Index/Send.php b/app/code/Magento/Wishlist/Controller/Index/Send.php index c2389af6a2282..e28da2fec4421 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Send.php +++ b/app/code/Magento/Wishlist/Controller/Index/Send.php @@ -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', diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/SendTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/SendTest.php index a8c0fbb951cce..766f3f0d4eddf 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/SendTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/SendTest.php @@ -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); @@ -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) diff --git a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php index 18b241d77a426..2191e20e6f5d3 100644 --- a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php +++ b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php @@ -86,6 +86,9 @@ class TransportBuilder */ protected $mailTransportFactory; + /** @var int|null */ + private $scopeId; + /** * @param FactoryInterface $templateFactory * @param MessageInterface $message @@ -158,6 +161,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 * @@ -166,7 +181,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; } @@ -244,6 +259,7 @@ protected function reset() $this->templateIdentifier = null; $this->templateVars = null; $this->templateOptions = null; + $this->scopeId = null; return $this; }