-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
11740: Sending emails from Admin in Multi-Store Environment defaults to Primary Store #11992
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9193745
11740: Sending emails from Admin in Multi-Store Environment defaults …
RomaKis ef03b52
11740: Sending emails from Admin in Multi-Store Environment defaults …
RomaKis f2bfdd9
11740: Sending emails from Admin in Multi-Store Environment defaults …
RomaKis b6764c8
Merge branch '2.2-develop' into 11740
RomaKis b322718
11740: Sending emails from Admin in Multi-Store Environment defaults …
RomaKis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to introduce another class and method instead of just adding an optional parameter
scopeId
to\Magento\Framework\Mail\Template\TransportBuilder::setFrom
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ishakhsuvarov, is it allowed? According to the backward compatibility(http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/index.html) seems it is prohibited.
May I add optional parameter scopeId?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I overlooked that for this case