Skip to content

Commit

Permalink
Confirmation emails have no FROM or FROM email address 2.2.4 magento#…
Browse files Browse the repository at this point in the history
…14952. Undone commit f2bfdd9 which caused issue
  • Loading branch information
sashas777 committed May 4, 2018
1 parent aca8c0b commit da9b12e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 142 deletions.
16 changes: 2 additions & 14 deletions app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php
100644 → 100755
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->setFromByStore(
$this->identityContainer->getEmailIdentity(),
$this->identityContainer->getStore()->getId()
);
Expand Down
13 changes: 3 additions & 10 deletions app/code/Magento/Sales/Test/Unit/Model/Order/Email/SenderBuilderTest.php
100644 → 100755
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,10 +76,10 @@ protected function setUp()
'setTemplateIdentifier',
'setTemplateOptions',
'setTemplateVars',
'setFromByStore'
]
);

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

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

Expand All @@ -120,8 +114,7 @@ protected function setUp()
$this->senderBuilder = new SenderBuilder(
$this->templateContainerMock,
$this->identityContainerMock,
$this->transportBuilder,
$this->transportBuilderByStore
$this->transportBuilder
);
}

Expand Down
16 changes: 16 additions & 0 deletions lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,20 @@ protected function prepareMessage()

return $this;
}

/**
* 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;
}
}

This file was deleted.

This file was deleted.

19 changes: 19 additions & 0 deletions lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,23 @@ public function testSetReplyTo()

$this->builder->setReplyTo('replyTo@example.com', 'replyName');
}

/**
* @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);
}
}

0 comments on commit da9b12e

Please sign in to comment.