Skip to content

Commit d196dcc

Browse files
committed
MAGETWO-96712: RMA return emails are populated with the wrong variables (not from the configured scope)
1 parent aa0c29d commit d196dcc

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ class TransportBuilder
4848
*/
4949
protected $templateOptions;
5050

51+
/**
52+
* Mail from address
53+
*
54+
* @var string|array
55+
*/
56+
private $from;
57+
5158
/**
5259
* Mail Transport
5360
*
@@ -178,8 +185,7 @@ public function setReplyTo($email, $name = null)
178185
*/
179186
public function setFrom($from)
180187
{
181-
$result = $this->_senderResolver->resolve($from);
182-
$this->message->setFrom($result['email'], $result['name']);
188+
$this->from = $from;
183189
return $this;
184190
}
185191

@@ -256,6 +262,7 @@ protected function reset()
256262
$this->templateIdentifier = null;
257263
$this->templateVars = null;
258264
$this->templateOptions = null;
265+
$this->from = null;
259266
return $this;
260267
}
261268

@@ -289,6 +296,14 @@ protected function prepareMessage()
289296
->setBody($body)
290297
->setSubject(html_entity_decode($template->getSubject(), ENT_QUOTES));
291298

299+
if ($this->from) {
300+
$from = $this->_senderResolver->resolve(
301+
$this->from,
302+
$template->getDesignConfig()->getStore()
303+
);
304+
$this->message->setFrom($from['email'], $from['name']);
305+
}
306+
292307
return $this;
293308
}
294309
}

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Framework\Mail\Test\Unit\Template;
88

99
use Magento\Framework\App\TemplateTypesInterface;
10+
use Magento\Framework\DataObject;
1011
use Magento\Framework\Mail\MessageInterface;
1112

1213
/**
@@ -99,17 +100,37 @@ protected function setUp()
99100
*/
100101
public function testGetTransport($templateType, $messageType, $bodyText, $templateNamespace)
101102
{
102-
$this->builder->setTemplateModel($templateNamespace);
103-
104103
$vars = ['reason' => 'Reason', 'customer' => 'Customer'];
105104
$options = ['area' => 'frontend', 'store' => 1];
105+
$from = 'email_from';
106+
$sender = ['email' => 'from@example.com', 'name' => 'name'];
106107

107-
$template = $this->createMock(\Magento\Framework\Mail\TemplateInterface::class);
108+
$this->builder->setTemplateModel($templateNamespace);
109+
$this->builder->setFrom($from);
110+
111+
$template = $this->createPartialMock(
112+
\Magento\Framework\Mail\TemplateInterface::class,
113+
[
114+
'setVars',
115+
'isPlain',
116+
'setOptions',
117+
'getSubject',
118+
'getType',
119+
'processTemplate',
120+
'getDesignConfig',
121+
]
122+
);
108123
$template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->willReturnSelf();
109124
$template->expects($this->once())->method('setOptions')->with($this->equalTo($options))->willReturnSelf();
110125
$template->expects($this->once())->method('getSubject')->willReturn('Email Subject');
111126
$template->expects($this->once())->method('getType')->willReturn($templateType);
112127
$template->expects($this->once())->method('processTemplate')->willReturn($bodyText);
128+
$template->method('getDesignConfig')->willReturn(new DataObject($options));
129+
130+
$this->senderResolverMock->expects($this->once())
131+
->method('resolve')
132+
->with($from, 1)
133+
->willReturn($sender);
113134

114135
$this->templateFactoryMock->expects($this->once())
115136
->method('get')
@@ -128,6 +149,9 @@ public function testGetTransport($templateType, $messageType, $bodyText, $templa
128149
->method('setBody')
129150
->with($this->equalTo($bodyText))
130151
->willReturnSelf();
152+
$this->messageMock->method('setFrom')
153+
->with($sender['email'], $sender['name'])
154+
->willReturnSelf();
131155

132156
$transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class);
133157

@@ -161,24 +185,6 @@ public function getTransportDataProvider()
161185
];
162186
}
163187

164-
/**
165-
* @return void
166-
*/
167-
public function testSetFrom()
168-
{
169-
$sender = ['email' => 'from@example.com', 'name' => 'name'];
170-
$this->senderResolverMock->expects($this->once())
171-
->method('resolve')
172-
->with($sender)
173-
->willReturn($sender);
174-
$this->messageMock->expects($this->once())
175-
->method('setFrom')
176-
->with('from@example.com', 'name')
177-
->willReturnSelf();
178-
179-
$this->builder->setFrom($sender);
180-
}
181-
182188
/**
183189
* @return void
184190
*/

0 commit comments

Comments
 (0)