Skip to content

Commit 9193745

Browse files
committed
11740: Sending emails from Admin in Multi-Store Environment defaults to Primary Store
1 parent b61725e commit 9193745

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ protected function configureEmailTemplate()
9898
$this->transportBuilder->setTemplateIdentifier($this->templateContainer->getTemplateId());
9999
$this->transportBuilder->setTemplateOptions($this->templateContainer->getTemplateOptions());
100100
$this->transportBuilder->setTemplateVars($this->templateContainer->getTemplateVars());
101-
$this->transportBuilder->setFrom($this->identityContainer->getEmailIdentity());
101+
$this->transportBuilder->setFromByStore(
102+
$this->identityContainer->getEmailIdentity(),
103+
$this->identityContainer->getStore()->getId()
104+
);
102105
}
103106
}

app/code/Magento/Sales/Test/Unit/Model/Order/Email/SenderBuilderTest.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Sales\Test\Unit\Model\Order\Email;
78

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

33+
/**
34+
* @var \PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $storeMock;
37+
3238
protected function setUp()
3339
{
3440
$templateId = 'test_template_id';
@@ -42,7 +48,11 @@ protected function setUp()
4248
['getTemplateVars', 'getTemplateOptions', 'getTemplateId']
4349
);
4450

45-
$this->storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getStoreId', '__wakeup']);
51+
$this->storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, [
52+
'getStoreId',
53+
'__wakeup',
54+
'getId',
55+
]);
4656

4757
$this->identityContainerMock = $this->createPartialMock(
4858
\Magento\Sales\Model\Order\Email\Container\ShipmentIdentity::class,
@@ -52,14 +62,20 @@ protected function setUp()
5262
'getCustomerName',
5363
'getTemplateOptions',
5464
'getEmailCopyTo',
55-
'getCopyMethod'
65+
'getCopyMethod',
66+
'getStore',
5667
]
5768
);
5869

59-
$this->transportBuilder = $this->createPartialMock(\Magento\Framework\Mail\Template\TransportBuilder::class, [
60-
'addTo', 'addBcc', 'getTransport',
61-
'setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars',
62-
'setFrom',
70+
$this->transportBuilder = $this->createPartialMock(\Magento\Framework\Mail\Template\TransportBuilder::class,
71+
[
72+
'addTo',
73+
'addBcc',
74+
'getTransport',
75+
'setTemplateIdentifier',
76+
'setTemplateOptions',
77+
'setTemplateVars',
78+
'setFromByStore',
6379
]);
6480

6581
$this->templateContainerMock->expects($this->once())
@@ -85,7 +101,7 @@ protected function setUp()
85101
->method('getEmailIdentity')
86102
->will($this->returnValue($emailIdentity));
87103
$this->transportBuilder->expects($this->once())
88-
->method('setFrom')
104+
->method('setFromByStore')
89105
->with($this->equalTo($emailIdentity));
90106

91107
$this->identityContainerMock->expects($this->once())
@@ -119,6 +135,12 @@ public function testSend()
119135
$this->identityContainerMock->expects($this->once())
120136
->method('getCustomerName')
121137
->will($this->returnValue($customerName));
138+
$this->identityContainerMock->expects($this->once())
139+
->method('getStore')
140+
->willReturn($this->storeMock);
141+
$this->storeMock->expects($this->once())
142+
->method('getId')
143+
->willReturn(1);
122144
$this->transportBuilder->expects($this->once())
123145
->method('addTo')
124146
->with($this->equalTo($customerEmail), $this->equalTo($customerName));
@@ -145,7 +167,12 @@ public function testSendCopyTo()
145167
$this->transportBuilder->expects($this->once())
146168
->method('addTo')
147169
->with($this->equalTo('[email protected]'));
148-
170+
$this->identityContainerMock->expects($this->once())
171+
->method('getStore')
172+
->willReturn($this->storeMock);
173+
$this->storeMock->expects($this->once())
174+
->method('getId')
175+
->willReturn(1);
149176
$this->transportBuilder->expects($this->once())
150177
->method('getTransport')
151178
->will($this->returnValue($transportMock));

lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ public function setFrom($from)
171171
return $this;
172172
}
173173

174+
/**
175+
* Set mail from address by store.
176+
*
177+
* @param string|array $from
178+
* @param string|int $store
179+
* @return $this
180+
*/
181+
public function setFromByStore($from, $store)
182+
{
183+
$result = $this->_senderResolver->resolve($from, $store);
184+
$this->message->setFrom($result['email'], $result['name']);
185+
return $this;
186+
}
187+
174188
/**
175189
* Set template identifier
176190
*

lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Framework\Mail\Test\Unit\Template;
78

89
use Magento\Framework\App\TemplateTypesInterface;
@@ -167,6 +168,25 @@ public function testSetFrom()
167168
$this->builder->setFrom($sender);
168169
}
169170

171+
/**
172+
* @return void
173+
*/
174+
public function setFromByStore()
175+
{
176+
$sender = ['email' => '[email protected]', 'name' => 'name'];
177+
$store = 1;
178+
$this->senderResolverMock->expects($this->once())
179+
->method('resolve')
180+
->with($sender, $store)
181+
->willReturn($sender);
182+
$this->messageMock->expects($this->once())
183+
->method('setFrom')
184+
->with('[email protected]', 'name')
185+
->willReturnSelf();
186+
187+
$this->builder->setFromByStore($sender);
188+
}
189+
170190
/**
171191
* @return void
172192
*/

0 commit comments

Comments
 (0)