Skip to content

Commit 1c0d274

Browse files
ENGCOM-4512: #21786 Fixed asynchronous email sending for the sales entities which were created with disabled email sending #21788
- Merge Pull Request #21788 from serhiyzhovnir/magento2:issue-21786-fix-asynchronous-email-sending-for-the-sales-entities-which-were-created-with-disabled-email-sending - Merged commits: 1. 8ed9266 2. 3ebdbff 3. 17cd172
2 parents 7b1cd79 + 17cd172 commit 1c0d274

File tree

12 files changed

+38
-24
lines changed

12 files changed

+38
-24
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
249249

250250
$this->creditmemoMock->expects($this->once())
251251
->method('setSendEmail')
252-
->with(true);
252+
->with($emailSendingResult);
253253

254254
if (!$configValue || $forceSyncMode) {
255255
$transport = [
@@ -279,7 +279,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending
279279
->method('setTemplateVars')
280280
->with($transport->getData());
281281

282-
$this->identityContainerMock->expects($this->once())
282+
$this->identityContainerMock->expects($this->exactly(2))
283283
->method('isEnabled')
284284
->willReturn($emailSendingResult);
285285

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
9090

9191
$this->creditmemoMock->expects($this->once())
9292
->method('setSendEmail')
93-
->with(true);
93+
->with($emailSendingResult);
9494

9595
$this->globalConfig->expects($this->once())
9696
->method('getValue')
@@ -130,7 +130,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
130130
]
131131
);
132132

133-
$this->identityContainerMock->expects($this->once())
133+
$this->identityContainerMock->expects($this->exactly(2))
134134
->method('isEnabled')
135135
->willReturn($emailSendingResult);
136136

@@ -197,6 +197,8 @@ public function sendDataProvider()
197197
* @param bool $isVirtualOrder
198198
* @param int $formatCallCount
199199
* @param string|null $expectedShippingAddress
200+
*
201+
* @return void
200202
* @dataProvider sendVirtualOrderDataProvider
201203
*/
202204
public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
@@ -207,7 +209,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
207209

208210
$this->creditmemoMock->expects($this->once())
209211
->method('setSendEmail')
210-
->with(true);
212+
->with(false);
211213

212214
$this->globalConfig->expects($this->once())
213215
->method('getValue')
@@ -242,7 +244,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
242244
]
243245
);
244246

245-
$this->identityContainerMock->expects($this->once())
247+
$this->identityContainerMock->expects($this->exactly(2))
246248
->method('isEnabled')
247249
->willReturn(false);
248250

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
9090

9191
$this->invoiceMock->expects($this->once())
9292
->method('setSendEmail')
93-
->with(true);
93+
->with($emailSendingResult);
9494

9595
$this->globalConfig->expects($this->once())
9696
->method('getValue')
@@ -136,7 +136,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
136136
]
137137
);
138138

139-
$this->identityContainerMock->expects($this->once())
139+
$this->identityContainerMock->expects($this->exactly(2))
140140
->method('isEnabled')
141141
->willReturn($emailSendingResult);
142142

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

213213
$this->invoiceMock->expects($this->once())
214214
->method('setSendEmail')
215-
->with(true);
215+
->with(false);
216216

217217
$this->globalConfig->expects($this->once())
218218
->method('getValue')
@@ -247,7 +247,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
247247
]
248248
);
249249

250-
$this->identityContainerMock->expects($this->once())
250+
$this->identityContainerMock->expects($this->exactly(2))
251251
->method('isEnabled')
252252
->willReturn(false);
253253

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
9090

9191
$this->shipmentMock->expects($this->once())
9292
->method('setSendEmail')
93-
->with(true);
93+
->with($emailSendingResult);
9494

9595
$this->globalConfig->expects($this->once())
9696
->method('getValue')
@@ -136,7 +136,7 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
136136
]
137137
);
138138

139-
$this->identityContainerMock->expects($this->once())
139+
$this->identityContainerMock->expects($this->exactly(2))
140140
->method('isEnabled')
141141
->willReturn($emailSendingResult);
142142

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

213213
$this->shipmentMock->expects($this->once())
214214
->method('setSendEmail')
215-
->with(true);
215+
->with(false);
216216

217217
$this->globalConfig->expects($this->once())
218218
->method('getValue')
@@ -247,7 +247,7 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
247247
]
248248
);
249249

250-
$this->identityContainerMock->expects($this->once())
250+
$this->identityContainerMock->expects($this->exactly(2))
251251
->method('isEnabled')
252252
->willReturn(false);
253253
$this->shipmentResourceMock->expects($this->once())

0 commit comments

Comments
 (0)