Skip to content
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

Alternative fix for Multi Store Emails issue, Fix Async Emails issues, Fix Multiple Email issues. #16461

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/
namespace Magento\Sales\Model\Order\Email;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\Mail\Template\TransportBuilderByStore;
use Magento\Sales\Model\Order\Email\Container\IdentityInterface;
use Magento\Sales\Model\Order\Email\Container\Template;

Expand All @@ -28,29 +26,19 @@ class SenderBuilder
*/
protected $transportBuilder;

/**
* @var TransportBuilderByStore
*/
private $transportBuilderByStore;

/**
* @param Template $templateContainer
* @param IdentityInterface $identityContainer
* @param TransportBuilder $transportBuilder
* @param TransportBuilderByStore $transportBuilderByStore
*/
public function __construct(
Template $templateContainer,
IdentityInterface $identityContainer,
TransportBuilder $transportBuilder,
TransportBuilderByStore $transportBuilderByStore = null
TransportBuilder $transportBuilder
) {
$this->templateContainer = $templateContainer;
$this->identityContainer = $identityContainer;
$this->transportBuilder = $transportBuilder;
$this->transportBuilderByStore = $transportBuilderByStore ?: ObjectManager::getInstance()->get(
TransportBuilderByStore::class
);
}

/**
Expand Down Expand Up @@ -110,7 +98,7 @@ protected function configureEmailTemplate()
$this->transportBuilder->setTemplateIdentifier($this->templateContainer->getTemplateId());
$this->transportBuilder->setTemplateOptions($this->templateContainer->getTemplateOptions());
$this->transportBuilder->setTemplateVars($this->templateContainer->getTemplateVars());
$this->transportBuilderByStore->setFromByStore(
$this->transportBuilder->setFrom(
$this->identityContainer->getEmailIdentity(),
$this->identityContainer->getStore()->getId()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Magento\Sales\Test\Unit\Model\Order\Email;

use Magento\Framework\Mail\Template\TransportBuilderByStore;
use Magento\Sales\Model\Order\Email\SenderBuilder;

class SenderBuilderTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -36,11 +35,6 @@ class SenderBuilderTest extends \PHPUnit\Framework\TestCase
*/
private $storeMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $transportBuilderByStore;

protected function setUp()
{
$templateId = 'test_template_id';
Expand Down Expand Up @@ -82,11 +76,10 @@ protected function setUp()
'setTemplateIdentifier',
'setTemplateOptions',
'setTemplateVars',
'setFrom',
]
);

$this->transportBuilderByStore = $this->createMock(TransportBuilderByStore::class);

$this->templateContainerMock->expects($this->once())
->method('getTemplateId')
->will($this->returnValue($templateId));
Expand All @@ -109,8 +102,8 @@ protected function setUp()
$this->identityContainerMock->expects($this->once())
->method('getEmailIdentity')
->will($this->returnValue($emailIdentity));
$this->transportBuilderByStore->expects($this->once())
->method('setFromByStore')
$this->transportBuilder->expects($this->once())
->method('setFrom')
->with($this->equalTo($emailIdentity));

$this->identityContainerMock->expects($this->once())
Expand All @@ -120,15 +113,16 @@ protected function setUp()
$this->senderBuilder = new SenderBuilder(
$this->templateContainerMock,
$this->identityContainerMock,
$this->transportBuilder,
$this->transportBuilderByStore
$this->transportBuilder
);
}

public function testSend()
{
$customerName = 'test_name';
$customerEmail = 'test_email';
$identity = 'email_identity_test';

$transportMock = $this->createMock(
\Magento\Sales\Test\Unit\Model\Order\Email\Stub\TransportInterfaceMock::class
);
Expand All @@ -151,6 +145,9 @@ public function testSend()
$this->storeMock->expects($this->once())
->method('getId')
->willReturn(1);
$this->transportBuilder->expects($this->once())
->method('setFrom')
->with($identity, 1);
$this->transportBuilder->expects($this->once())
->method('addTo')
->with($this->equalTo($customerEmail), $this->equalTo($customerName));
Expand All @@ -164,6 +161,7 @@ public function testSend()

public function testSendCopyTo()
{
$identity = 'email_identity_test';
$transportMock = $this->createMock(
\Magento\Sales\Test\Unit\Model\Order\Email\Stub\TransportInterfaceMock::class
);
Expand All @@ -177,6 +175,9 @@ public function testSendCopyTo()
$this->transportBuilder->expects($this->once())
->method('addTo')
->with($this->equalTo('example@mail.com'));
$this->transportBuilder->expects($this->once())
->method('setFrom')
->with($identity, 1);
$this->identityContainerMock->expects($this->once())
->method('getStore')
->willReturn($this->storeMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public function setReplyTo($email, $name = null)
* @param string|array $from
* @return $this
*/
public function setFrom($from)
public function setFrom($from, $store = null)
{
$result = $this->_senderResolver->resolve($from);
$result = $this->_senderResolver->resolve($from, $store);
$this->message->setFrom($result['email'], $result['name']);
return $this;
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,17 @@ public function getTransportDataProvider()
public function testSetFrom()
{
$sender = ['email' => 'from@example.com', 'name' => 'name'];
$store = 1;
$this->senderResolverMock->expects($this->once())
->method('resolve')
->with($sender)
->with($sender, $store)
->willReturn($sender);
$this->messageMock->expects($this->once())
->method('setFrom')
->with('from@example.com', 'name')
->willReturnSelf();

$this->builder->setFrom($sender);
$this->builder->setFrom($sender, $store);
}

/**
Expand Down