Skip to content

Commit 84826f9

Browse files
authored
ENGCOM-4512: #21786 Fixed asynchronous email sending for the sales entities which were created with disabled email sending #21788
2 parents ad95ff9 + 78e98e4 commit 84826f9

File tree

12 files changed

+50
-28
lines changed

12 files changed

+50
-28
lines changed

app/code/Magento/Sales/Model/Order/Creditmemo/Sender/EmailSender.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ public function __construct(
8989
* @param bool $forceSyncMode
9090
*
9191
* @return bool
92+
* @throws \Exception
9293
*/
9394
public function send(
9495
\Magento\Sales\Api\Data\OrderInterface $order,
9596
\Magento\Sales\Api\Data\CreditmemoInterface $creditmemo,
9697
\Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment = null,
9798
$forceSyncMode = false
9899
) {
99-
$creditmemo->setSendEmail(true);
100+
$creditmemo->setSendEmail($this->identityContainer->isEnabled());
100101

101102
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
102103
$transport = [
@@ -145,6 +146,7 @@ public function send(
145146
* @param \Magento\Sales\Api\Data\OrderInterface $order
146147
*
147148
* @return string
149+
* @throws \Exception
148150
*/
149151
private function getPaymentHtml(\Magento\Sales\Api\Data\OrderInterface $order)
150152
{

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class CreditmemoSender extends Sender
5757
* @param CreditmemoIdentity $identityContainer
5858
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
5959
* @param \Psr\Log\LoggerInterface $logger
60+
* @param Renderer $addressRenderer
6061
* @param PaymentHelper $paymentHelper
6162
* @param CreditmemoResource $creditmemoResource
6263
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
63-
* @param Renderer $addressRenderer
6464
* @param ManagerInterface $eventManager
6565
*/
6666
public function __construct(
@@ -96,10 +96,11 @@ public function __construct(
9696
* @param Creditmemo $creditmemo
9797
* @param bool $forceSyncMode
9898
* @return bool
99+
* @throws \Exception
99100
*/
100101
public function send(Creditmemo $creditmemo, $forceSyncMode = false)
101102
{
102-
$creditmemo->setSendEmail(true);
103+
$creditmemo->setSendEmail($this->identityContainer->isEnabled());
103104

104105
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
105106
$order = $creditmemo->getOrder();
@@ -146,6 +147,7 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false)
146147
*
147148
* @param Order $order
148149
* @return string
150+
* @throws \Exception
149151
*/
150152
protected function getPaymentHtml(Order $order)
151153
{

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class InvoiceSender extends Sender
5757
* @param InvoiceIdentity $identityContainer
5858
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
5959
* @param \Psr\Log\LoggerInterface $logger
60+
* @param Renderer $addressRenderer
6061
* @param PaymentHelper $paymentHelper
6162
* @param InvoiceResource $invoiceResource
6263
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
63-
* @param Renderer $addressRenderer
6464
* @param ManagerInterface $eventManager
6565
*/
6666
public function __construct(
@@ -96,10 +96,11 @@ public function __construct(
9696
* @param Invoice $invoice
9797
* @param bool $forceSyncMode
9898
* @return bool
99+
* @throws \Exception
99100
*/
100101
public function send(Invoice $invoice, $forceSyncMode = false)
101102
{
102-
$invoice->setSendEmail(true);
103+
$invoice->setSendEmail($this->identityContainer->isEnabled());
103104

104105
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
105106
$order = $invoice->getOrder();
@@ -146,6 +147,7 @@ public function send(Invoice $invoice, $forceSyncMode = false)
146147
*
147148
* @param Order $order
148149
* @return string
150+
* @throws \Exception
149151
*/
150152
protected function getPaymentHtml(Order $order)
151153
{

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class ShipmentSender extends Sender
5757
* @param ShipmentIdentity $identityContainer
5858
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
5959
* @param \Psr\Log\LoggerInterface $logger
60+
* @param Renderer $addressRenderer
6061
* @param PaymentHelper $paymentHelper
6162
* @param ShipmentResource $shipmentResource
6263
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
63-
* @param Renderer $addressRenderer
6464
* @param ManagerInterface $eventManager
6565
*/
6666
public function __construct(
@@ -96,10 +96,11 @@ public function __construct(
9696
* @param Shipment $shipment
9797
* @param bool $forceSyncMode
9898
* @return bool
99+
* @throws \Exception
99100
*/
100101
public function send(Shipment $shipment, $forceSyncMode = false)
101102
{
102-
$shipment->setSendEmail(true);
103+
$shipment->setSendEmail($this->identityContainer->isEnabled());
103104

104105
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
105106
$order = $shipment->getOrder();
@@ -146,6 +147,7 @@ public function send(Shipment $shipment, $forceSyncMode = false)
146147
*
147148
* @param Order $order
148149
* @return string
150+
* @throws \Exception
149151
*/
150152
protected function getPaymentHtml(Order $order)
151153
{

app/code/Magento/Sales/Model/Order/Invoice/Sender/EmailSender.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ public function __construct(
8989
* @param bool $forceSyncMode
9090
*
9191
* @return bool
92+
* @throws \Exception
9293
*/
9394
public function send(
9495
\Magento\Sales\Api\Data\OrderInterface $order,
9596
\Magento\Sales\Api\Data\InvoiceInterface $invoice,
9697
\Magento\Sales\Api\Data\InvoiceCommentCreationInterface $comment = null,
9798
$forceSyncMode = false
9899
) {
99-
$invoice->setSendEmail(true);
100+
$invoice->setSendEmail($this->identityContainer->isEnabled());
100101

101102
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
102103
$transport = [
@@ -145,6 +146,7 @@ public function send(
145146
* @param \Magento\Sales\Api\Data\OrderInterface $order
146147
*
147148
* @return string
149+
* @throws \Exception
148150
*/
149151
private function getPaymentHtml(\Magento\Sales\Api\Data\OrderInterface $order)
150152
{

app/code/Magento/Sales/Model/Order/Shipment/Sender/EmailSender.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ public function __construct(
8989
* @param bool $forceSyncMode
9090
*
9191
* @return bool
92+
* @throws \Exception
9293
*/
9394
public function send(
9495
\Magento\Sales\Api\Data\OrderInterface $order,
9596
\Magento\Sales\Api\Data\ShipmentInterface $shipment,
9697
\Magento\Sales\Api\Data\ShipmentCommentCreationInterface $comment = null,
9798
$forceSyncMode = false
9899
) {
99-
$shipment->setSendEmail(true);
100+
$shipment->setSendEmail($this->identityContainer->isEnabled());
100101

101102
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
102103
$transport = [
@@ -145,6 +146,7 @@ public function send(
145146
* @param \Magento\Sales\Api\Data\OrderInterface $order
146147
*
147148
* @return string
149+
* @throws \Exception
148150
*/
149151
private function getPaymentHtml(\Magento\Sales\Api\Data\OrderInterface $order)
150152
{

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
@@ -249,7 +248,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
249248

250249
$this->creditmemoMock->expects($this->once())
251250
->method('setSendEmail')
252-
->with(true);
251+
->with($emailSendingResult);
253252

254253
if (!$configValue || $forceSyncMode) {
255254
$transport = [
@@ -279,7 +278,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
279278
->method('setTemplateVars')
280279
->with($transport->getData());
281280

282-
$this->identityContainerMock->expects($this->once())
281+
$this->identityContainerMock->expects($this->exactly(2))
283282
->method('isEnabled')
284283
->willReturn($emailSendingResult);
285284

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
99

10+
/**
11+
* Test for Magento\Sales\Model\Order\Email\Sender\CreditmemoSender class.
12+
*/
1013
class CreditmemoSenderTest extends AbstractSenderTest
1114
{
1215
/**
@@ -90,7 +93,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
9093

9194
$this->creditmemoMock->expects($this->once())
9295
->method('setSendEmail')
93-
->with(true);
96+
->with($emailSendingResult);
9497

9598
$this->globalConfig->expects($this->once())
9699
->method('getValue')
@@ -130,7 +133,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
130133
]
131134
);
132135

133-
$this->identityContainerMock->expects($this->once())
136+
$this->identityContainerMock->expects($this->exactly(2))
134137
->method('isEnabled')
135138
->willReturn($emailSendingResult);
136139

@@ -197,6 +200,8 @@ public function sendDataProvider()
197200
* @param bool $isVirtualOrder
198201
* @param int $formatCallCount
199202
* @param string|null $expectedShippingAddress
203+
*
204+
* @return void
200205
* @dataProvider sendVirtualOrderDataProvider
201206
*/
202207
public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
@@ -207,7 +212,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
207212

208213
$this->creditmemoMock->expects($this->once())
209214
->method('setSendEmail')
210-
->with(true);
215+
->with(false);
211216

212217
$this->globalConfig->expects($this->once())
213218
->method('getValue')
@@ -242,7 +247,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
242247
]
243248
);
244249

245-
$this->identityContainerMock->expects($this->once())
250+
$this->identityContainerMock->expects($this->exactly(2))
246251
->method('isEnabled')
247252
->willReturn(false);
248253

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
99

10+
/**
11+
* Test for Magento\Sales\Model\Order\Email\Sender\InvoiceSender class.
12+
*/
1013
class InvoiceSenderTest extends AbstractSenderTest
1114
{
1215
/**
@@ -90,7 +93,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
9093

9194
$this->invoiceMock->expects($this->once())
9295
->method('setSendEmail')
93-
->with(true);
96+
->with($emailSendingResult);
9497

9598
$this->globalConfig->expects($this->once())
9699
->method('getValue')
@@ -136,7 +139,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
136139
]
137140
);
138141

139-
$this->identityContainerMock->expects($this->once())
142+
$this->identityContainerMock->expects($this->exactly(2))
140143
->method('isEnabled')
141144
->willReturn($emailSendingResult);
142145

@@ -212,7 +215,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
212215

213216
$this->invoiceMock->expects($this->once())
214217
->method('setSendEmail')
215-
->with(true);
218+
->with(false);
216219

217220
$this->globalConfig->expects($this->once())
218221
->method('getValue')
@@ -247,7 +250,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
247250
]
248251
);
249252

250-
$this->identityContainerMock->expects($this->once())
253+
$this->identityContainerMock->expects($this->exactly(2))
251254
->method('isEnabled')
252255
->willReturn(false);
253256

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Sales\Model\Order\Email\Sender\ShipmentSender;
99

10+
/**
11+
* Test for Magento\Sales\Model\Order\Email\Sender\ShipmentSender class.
12+
*/
1013
class ShipmentSenderTest extends AbstractSenderTest
1114
{
1215
/**
@@ -90,7 +93,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
9093

9194
$this->shipmentMock->expects($this->once())
9295
->method('setSendEmail')
93-
->with(true);
96+
->with($emailSendingResult);
9497

9598
$this->globalConfig->expects($this->once())
9699
->method('getValue')
@@ -136,7 +139,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
136139
]
137140
);
138141

139-
$this->identityContainerMock->expects($this->once())
142+
$this->identityContainerMock->expects($this->exactly(2))
140143
->method('isEnabled')
141144
->willReturn($emailSendingResult);
142145

@@ -212,7 +215,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
212215

213216
$this->shipmentMock->expects($this->once())
214217
->method('setSendEmail')
215-
->with(true);
218+
->with(false);
216219

217220
$this->globalConfig->expects($this->once())
218221
->method('getValue')
@@ -247,7 +250,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
247250
]
248251
);
249252

250-
$this->identityContainerMock->expects($this->once())
253+
$this->identityContainerMock->expects($this->exactly(2))
251254
->method('isEnabled')
252255
->willReturn(false);
253256
$this->shipmentResourceMock->expects($this->once())

0 commit comments

Comments
 (0)