-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⏫ Forwardport of #11992 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/11992.patch (created by @RomaKis) based on commit(s): 1. 9193745 2. ef03b52 3. f2bfdd9 4. b6764c8 5. b322718 Fixed GitHub Issues in 2.3-develop branch: - #11740: Sending emails from Admin in Multi-Store Environment defaults to Primary Store (reported by @lee586)
- Loading branch information
1 parent
8e77e2f
commit cc2b11f
Showing
5 changed files
with
184 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
lib/internal/Magento/Framework/Mail/Template/TransportBuilderByStore.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Mail\Template; | ||
|
||
use Magento\Framework\Mail\MessageInterface; | ||
|
||
class TransportBuilderByStore | ||
{ | ||
/** | ||
* Message. | ||
* | ||
* @var \Magento\Framework\Mail\Message | ||
*/ | ||
protected $message; | ||
|
||
/** | ||
* Sender resolver. | ||
* | ||
* @var \Magento\Framework\Mail\Template\SenderResolverInterface | ||
*/ | ||
private $senderResolver; | ||
|
||
/** | ||
* @param MessageInterface $message | ||
* @param SenderResolverInterface $senderResolver | ||
*/ | ||
public function __construct( | ||
MessageInterface $message, | ||
SenderResolverInterface $senderResolver | ||
) { | ||
$this->message = $message; | ||
$this->senderResolver = $senderResolver; | ||
} | ||
|
||
/** | ||
* Set mail from address by store. | ||
* | ||
* @param string|array $from | ||
* @param string|int $store | ||
* | ||
* @return $this | ||
*/ | ||
public function setFromByStore($from, $store) | ||
{ | ||
$result = $this->senderResolver->resolve($from, $store); | ||
$this->message->setFrom($result['email'], $result['name']); | ||
|
||
return $this; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderByStoreTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Mail\Test\Unit\Template; | ||
|
||
use Magento\Framework\Mail\Template\TransportBuilderByStore; | ||
|
||
class TransportBuilderByStoreTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var \Magento\Framework\Mail\Template\TransportBuilderByStore | ||
*/ | ||
protected $model; | ||
|
||
/** | ||
* @var \Magento\Framework\Mail\Message | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $messageMock; | ||
|
||
/** | ||
* @var \Magento\Framework\Mail\Template\SenderResolverInterface | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $senderResolverMock; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); | ||
$this->messageMock = $this->createMock(\Magento\Framework\Mail\Message::class); | ||
$this->senderResolverMock = $this->createMock(\Magento\Framework\Mail\Template\SenderResolverInterface::class); | ||
|
||
$this->model = $objectManagerHelper->getObject( | ||
TransportBuilderByStore::class, | ||
[ | ||
'message' => $this->messageMock, | ||
'senderResolver' => $this->senderResolverMock, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testSetFromByStore() | ||
{ | ||
$sender = ['email' => 'from@example.com', 'name' => 'name']; | ||
$store = 1; | ||
$this->senderResolverMock->expects($this->once()) | ||
->method('resolve') | ||
->with($sender, $store) | ||
->willReturn($sender); | ||
$this->messageMock->expects($this->once()) | ||
->method('setFrom') | ||
->with('from@example.com', 'name') | ||
->willReturnSelf(); | ||
|
||
$this->model->setFromByStore($sender, $store); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters