Skip to content

Commit

Permalink
11740: Sending emails from Admin in Multi-Store Environment defaults …
Browse files Browse the repository at this point in the history
…to Primary Store
  • Loading branch information
RomaKis committed Nov 3, 2017
1 parent b61725e commit 9193745
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
5 changes: 4 additions & 1 deletion app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ protected function configureEmailTemplate()
$this->transportBuilder->setTemplateIdentifier($this->templateContainer->getTemplateId());
$this->transportBuilder->setTemplateOptions($this->templateContainer->getTemplateOptions());
$this->transportBuilder->setTemplateVars($this->templateContainer->getTemplateVars());
$this->transportBuilder->setFrom($this->identityContainer->getEmailIdentity());
$this->transportBuilder->setFromByStore(
$this->identityContainer->getEmailIdentity(),
$this->identityContainer->getStore()->getId()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

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

use Magento\Sales\Model\Order\Email\SenderBuilder;
Expand All @@ -29,6 +30,11 @@ class SenderBuilderTest extends \PHPUnit\Framework\TestCase
*/
protected $transportBuilder;

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

protected function setUp()
{
$templateId = 'test_template_id';
Expand All @@ -42,7 +48,11 @@ protected function setUp()
['getTemplateVars', 'getTemplateOptions', 'getTemplateId']
);

$this->storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getStoreId', '__wakeup']);
$this->storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, [
'getStoreId',
'__wakeup',
'getId',
]);

$this->identityContainerMock = $this->createPartialMock(
\Magento\Sales\Model\Order\Email\Container\ShipmentIdentity::class,
Expand All @@ -52,14 +62,20 @@ protected function setUp()
'getCustomerName',
'getTemplateOptions',
'getEmailCopyTo',
'getCopyMethod'
'getCopyMethod',
'getStore',
]
);

$this->transportBuilder = $this->createPartialMock(\Magento\Framework\Mail\Template\TransportBuilder::class, [
'addTo', 'addBcc', 'getTransport',
'setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars',
'setFrom',
$this->transportBuilder = $this->createPartialMock(\Magento\Framework\Mail\Template\TransportBuilder::class,
[
'addTo',
'addBcc',
'getTransport',
'setTemplateIdentifier',
'setTemplateOptions',
'setTemplateVars',
'setFromByStore',
]);

$this->templateContainerMock->expects($this->once())
Expand All @@ -85,7 +101,7 @@ protected function setUp()
->method('getEmailIdentity')
->will($this->returnValue($emailIdentity));
$this->transportBuilder->expects($this->once())
->method('setFrom')
->method('setFromByStore')
->with($this->equalTo($emailIdentity));

$this->identityContainerMock->expects($this->once())
Expand Down Expand Up @@ -119,6 +135,12 @@ public function testSend()
$this->identityContainerMock->expects($this->once())
->method('getCustomerName')
->will($this->returnValue($customerName));
$this->identityContainerMock->expects($this->once())
->method('getStore')
->willReturn($this->storeMock);
$this->storeMock->expects($this->once())
->method('getId')
->willReturn(1);
$this->transportBuilder->expects($this->once())
->method('addTo')
->with($this->equalTo($customerEmail), $this->equalTo($customerName));
Expand All @@ -145,7 +167,12 @@ public function testSendCopyTo()
$this->transportBuilder->expects($this->once())
->method('addTo')
->with($this->equalTo('example@mail.com'));

$this->identityContainerMock->expects($this->once())
->method('getStore')
->willReturn($this->storeMock);
$this->storeMock->expects($this->once())
->method('getId')
->willReturn(1);
$this->transportBuilder->expects($this->once())
->method('getTransport')
->will($this->returnValue($transportMock));
Expand Down
14 changes: 14 additions & 0 deletions lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ public function setFrom($from)
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;
}

/**
* Set template identifier
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\Mail\Test\Unit\Template;

use Magento\Framework\App\TemplateTypesInterface;
Expand Down Expand Up @@ -167,6 +168,25 @@ public function testSetFrom()
$this->builder->setFrom($sender);
}

/**
* @return void
*/
public function setFromByStore()
{
$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->builder->setFromByStore($sender);
}

/**
* @return void
*/
Expand Down

0 comments on commit 9193745

Please sign in to comment.