Skip to content

Commit 863ec2e

Browse files
MC-18193: All Sales emails are being copied to the same customer when sales_emails cron has an error
1 parent 058e09b commit 863ec2e

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,9 @@ public function getTransport()
264264
try {
265265
$this->prepareMessage();
266266
$mailTransport = $this->mailTransportFactory->create(['message' => clone $this->message]);
267-
} catch (LocalizedException $e) {
267+
} finally {
268268
$this->reset();
269-
throw $e;
270269
}
271-
$this->reset();
272270

273271
return $mailTransport;
274272
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,34 @@ public function testGetTransport($templateType, $messageType, $bodyText, $templa
143143
$this->assertInstanceOf(\Magento\Framework\Mail\TransportInterface::class, $this->builder->getTransport());
144144
}
145145

146+
/**
147+
* Test get transport with exception
148+
*
149+
* @expectedException \Magento\Framework\Exception\LocalizedException
150+
* @expectedExceptionMessage Unknown template type
151+
*/
152+
public function testGetTransportWithException()
153+
{
154+
$this->builder->setTemplateModel('Test\Namespace\Template');
155+
156+
$vars = ['reason' => 'Reason', 'customer' => 'Customer'];
157+
$options = ['area' => 'frontend', 'store' => 1];
158+
159+
$template = $this->createMock(\Magento\Framework\Mail\TemplateInterface::class);
160+
$template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->willReturnSelf();
161+
$template->expects($this->once())->method('setOptions')->with($this->equalTo($options))->willReturnSelf();
162+
$template->expects($this->once())->method('getType')->willReturn('Unknown');
163+
$this->messageFactoryMock->expects($this->once())->method('create');
164+
$this->templateFactoryMock->expects($this->once())
165+
->method('get')
166+
->with($this->equalTo('identifier'), $this->equalTo('Test\Namespace\Template'))
167+
->willReturn($template);
168+
169+
$this->builder->setTemplateIdentifier('identifier')->setTemplateVars($vars)->setTemplateOptions($options);
170+
171+
$this->assertInstanceOf(\Magento\Framework\Mail\TransportInterface::class, $this->builder->getTransport());
172+
}
173+
146174
/**
147175
* @return array
148176
*/

0 commit comments

Comments
 (0)