Skip to content

Commit f005d0e

Browse files
committed
ACP2E-2734: Emails are failing to send
1 parent b8429cb commit f005d0e

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

app/code/Magento/Sales/Model/EmailSenderHandler.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,11 @@ public function sendEmails()
132132

133133
/** @var \Magento\Sales\Model\AbstractModel $item */
134134
foreach ($entityCollection->getItems() as $item) {
135-
if ($this->emailSender->send($item, true)) {
136-
$this->entityResource->saveAttribute(
137-
$item->setEmailSent(true),
138-
'email_sent'
139-
);
140-
} else {
141-
// When the email is failed to send, the email_sent attribute
142-
// should be set to false, preventing this email from being
143-
// sent over and over again in the next cron runs.
144-
$this->entityResource->saveAttribute(
145-
$item->setEmailSent(false),
146-
'email_sent'
147-
);
148-
}
135+
$isEmailSent = $this->emailSender->send($item, true);
136+
$this->entityResource->saveAttribute(
137+
$item->setEmailSent($isEmailSent),
138+
'email_sent'
139+
);
149140
}
150141
}
151142
}

app/code/Magento/Sales/Test/Unit/Model/EmailSenderHandlerTest.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,24 +245,16 @@ public function testExecute(
245245
->method('isEnabled')
246246
->willReturn(true);
247247

248-
if ($emailSendingResult) {
249-
$collectionItem
250-
->expects($this->once())
251-
->method('setEmailSent')
252-
->with(true)
253-
->willReturn($collectionItem);
254-
255-
$this->entityResource
256-
->expects($this->once())
257-
->method('saveAttribute')
258-
->with($collectionItem);
259-
} else {
260-
$collectionItem
261-
->expects($this->once())
262-
->method('setEmailSent')
263-
->with(false)
264-
->willReturn($collectionItem);
265-
}
248+
$collectionItem
249+
->expects($this->once())
250+
->method('setEmailSent')
251+
->with($emailSendingResult)
252+
->willReturn($collectionItem);
253+
254+
$this->entityResource
255+
->expects($this->once())
256+
->method('saveAttribute')
257+
->with($collectionItem);
266258
}
267259
}
268260

0 commit comments

Comments
 (0)