Skip to content

Commit 4f8d0c6

Browse files
authored
ENGCOM-5650: Allow sending email to BCC address when not notifying user. #22810
2 parents a0e7a54 + 878a2af commit 4f8d0c6

File tree

10 files changed

+53
-18
lines changed

10 files changed

+53
-18
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
/**
1414
* Class Sender
15-
* @api
1615
*
16+
* phpcs:disable Magento2.Classes.AbstractApi
17+
* @api
1718
* @since 100.0.2
1819
*/
1920
abstract class Sender
@@ -87,10 +88,12 @@ protected function checkAndSend(Order $order)
8788
$this->logger->error($e->getMessage());
8889
return false;
8990
}
90-
try {
91-
$sender->sendCopyTo();
92-
} catch (\Exception $e) {
93-
$this->logger->error($e->getMessage());
91+
if ($this->identityContainer->getCopyMethod() == 'copy') {
92+
try {
93+
$sender->sendCopyTo();
94+
} catch (\Exception $e) {
95+
$this->logger->error($e->getMessage());
96+
}
9497
}
9598
return true;
9699
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function sendCopyTo()
8484
{
8585
$copyTo = $this->identityContainer->getEmailCopyTo();
8686

87-
if (!empty($copyTo) && $this->identityContainer->getCopyMethod() == 'copy') {
87+
if (!empty($copyTo)) {
8888
$this->configureEmailTemplate();
8989
foreach ($copyTo as $email) {
9090
$this->transportBuilder->addTo($email);

app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Sender/EmailSenderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
283283
->willReturn($emailSendingResult);
284284

285285
if ($emailSendingResult) {
286+
$this->identityContainerMock->expects($this->once())
287+
->method('getCopyMethod')
288+
->willReturn('copy');
289+
286290
$this->senderBuilderFactoryMock->expects($this->once())
287291
->method('create')
288292
->willReturn($this->senderMock);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function setUp()
5757

5858
$this->identityContainerMock = $this->createPartialMock(
5959
\Magento\Sales\Model\Order\Email\Container\CreditmemoIdentity::class,
60-
['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId']
60+
['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId', 'getCopyMethod']
6161
);
6262
$this->identityContainerMock->expects($this->any())
6363
->method('getStore')
@@ -138,6 +138,10 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
138138
->willReturn($emailSendingResult);
139139

140140
if ($emailSendingResult) {
141+
$this->identityContainerMock->expects($this->once())
142+
->method('getCopyMethod')
143+
->willReturn('copy');
144+
141145
$this->senderBuilderFactoryMock->expects($this->once())
142146
->method('create')
143147
->willReturn($this->senderMock);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function setUp()
5757

5858
$this->identityContainerMock = $this->createPartialMock(
5959
\Magento\Sales\Model\Order\Email\Container\InvoiceIdentity::class,
60-
['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId']
60+
['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId', 'getCopyMethod']
6161
);
6262
$this->identityContainerMock->expects($this->any())
6363
->method('getStore')
@@ -144,6 +144,10 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
144144
->willReturn($emailSendingResult);
145145

146146
if ($emailSendingResult) {
147+
$this->identityContainerMock->expects($this->once())
148+
->method('getCopyMethod')
149+
->willReturn('copy');
150+
147151
$this->senderBuilderFactoryMock->expects($this->once())
148152
->method('create')
149153
->willReturn($this->senderMock);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp()
3030

3131
$this->identityContainerMock = $this->createPartialMock(
3232
\Magento\Sales\Model\Order\Email\Container\OrderIdentity::class,
33-
['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId']
33+
['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId', 'getCopyMethod']
3434
);
3535
$this->identityContainerMock->expects($this->any())
3636
->method('getStore')
@@ -77,6 +77,10 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult, $sen
7777
->willReturn($emailSendingResult);
7878

7979
if ($emailSendingResult) {
80+
$this->identityContainerMock->expects($senderSendException ? $this->never() : $this->once())
81+
->method('getCopyMethod')
82+
->willReturn('copy');
83+
8084
$addressMock = $this->createMock(\Magento\Sales\Model\Order\Address::class);
8185

8286
$this->addressRenderer->expects($this->any())
@@ -214,6 +218,10 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
214218
->method('isEnabled')
215219
->willReturn(true);
216220

221+
$this->identityContainerMock->expects($this->once())
222+
->method('getCopyMethod')
223+
->willReturn('copy');
224+
217225
$addressMock = $this->createMock(\Magento\Sales\Model\Order\Address::class);
218226

219227
$this->addressRenderer->expects($this->exactly($formatCallCount))

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function setUp()
5757

5858
$this->identityContainerMock = $this->createPartialMock(
5959
\Magento\Sales\Model\Order\Email\Container\ShipmentIdentity::class,
60-
['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId']
60+
['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId', 'getCopyMethod']
6161
);
6262
$this->identityContainerMock->expects($this->any())
6363
->method('getStore')
@@ -144,6 +144,10 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
144144
->willReturn($emailSendingResult);
145145

146146
if ($emailSendingResult) {
147+
$this->identityContainerMock->expects($this->once())
148+
->method('getCopyMethod')
149+
->willReturn('copy');
150+
147151
$this->senderBuilderFactoryMock->expects($this->once())
148152
->method('create')
149153
->willReturn($this->senderMock);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ protected function setUp()
4848
['getTemplateVars', 'getTemplateOptions', 'getTemplateId']
4949
);
5050

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

5760
$this->identityContainerMock = $this->createPartialMock(
5861
\Magento\Sales\Model\Order\Email\Container\ShipmentIdentity::class,
@@ -165,9 +168,6 @@ public function testSendCopyTo()
165168
$transportMock = $this->createMock(
166169
\Magento\Sales\Test\Unit\Model\Order\Email\Stub\TransportInterfaceMock::class
167170
);
168-
$this->identityContainerMock->expects($this->once())
169-
->method('getCopyMethod')
170-
->will($this->returnValue('copy'));
171171
$this->identityContainerMock->expects($this->never())
172172
->method('getCustomerEmail');
173173
$this->identityContainerMock->expects($this->never())

app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Sender/EmailSenderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
282282
->willReturn($emailSendingResult);
283283

284284
if ($emailSendingResult) {
285+
$this->identityContainerMock->expects($this->once())
286+
->method('getCopyMethod')
287+
->willReturn('copy');
288+
285289
$this->senderBuilderFactoryMock->expects($this->once())
286290
->method('create')
287291
->willReturn($this->senderMock);

app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/Sender/EmailSenderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
284284
->willReturn($emailSendingResult);
285285

286286
if ($emailSendingResult) {
287+
$this->identityContainerMock->expects($this->once())
288+
->method('getCopyMethod')
289+
->willReturn('copy');
290+
287291
$this->senderBuilderFactoryMock->expects($this->once())
288292
->method('create')
289293
->willReturn($this->senderMock);

0 commit comments

Comments
 (0)