Skip to content

Commit ac0500b

Browse files
committed
MC-38717: Sales emails asynchronous sending sends out old emails
1 parent 1c3e953 commit ac0500b

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class EmailSenderHandler
6969
*/
7070
private $localeDate;
7171

72+
/**
73+
* @var string
74+
*/
75+
private $modifyStartFromDate = '-1 day';
76+
7277
/**
7378
* @param \Magento\Sales\Model\Order\Email\Sender $emailSender
7479
* @param \Magento\Sales\Model\ResourceModel\EntityAbstract $entityResource
@@ -78,6 +83,7 @@ class EmailSenderHandler
7883
* @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
7984
* @param ValueFactory|null $configValueFactory
8085
* @param TimezoneInterface|null $localeDate
86+
* @param string|null $modifyStartFromDate
8187
*/
8288
public function __construct(
8389
\Magento\Sales\Model\Order\Email\Sender $emailSender,
@@ -87,7 +93,8 @@ public function __construct(
8793
IdentityInterface $identityContainer = null,
8894
\Magento\Store\Model\StoreManagerInterface $storeManager = null,
8995
?ValueFactory $configValueFactory = null,
90-
?TimezoneInterface $localeDate = null
96+
?TimezoneInterface $localeDate = null,
97+
?string $modifyStartFromDate = null
9198
) {
9299
$this->emailSender = $emailSender;
93100
$this->entityResource = $entityResource;
@@ -101,6 +108,7 @@ public function __construct(
101108

102109
$this->configValueFactory = $configValueFactory ?: ObjectManager::getInstance()->get(ValueFactory::class);
103110
$this->localeDate = $localeDate ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
111+
$this->modifyStartFromDate = $modifyStartFromDate ?: $this->modifyStartFromDate;
104112
}
105113

106114
/**
@@ -179,7 +187,7 @@ private function getStartFromDate(): string
179187

180188
if ($configValue->getId()) {
181189
$fromDate = $this->localeDate->date($configValue->getUpdatedAt())
182-
->modify('-1 day')->format('Y-m-d H:i:s');
190+
->modify($this->modifyStartFromDate)->format('Y-m-d H:i:s');
183191
}
184192

185193
return $fromDate;

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class EmailSenderHandlerTest extends TestCase
8585
*/
8686
private $localeDate;
8787

88+
/**
89+
* @var string
90+
*/
91+
private $modifyStartFromDate = '-1 day';
92+
8893
protected function setUp(): void
8994
{
9095
$objectManager = new ObjectManager($this);
@@ -135,14 +140,15 @@ protected function setUp(): void
135140
$this->object = $objectManager->getObject(
136141
EmailSenderHandler::class,
137142
[
138-
'emailSender' => $this->emailSender,
139-
'entityResource' => $this->entityResource,
140-
'entityCollection' => $this->entityCollection,
141-
'globalConfig' => $this->globalConfig,
142-
'identityContainer' => $this->identityContainerMock,
143-
'storeManager' => $this->storeManagerMock,
144-
'configValueFactory' => $this->configValueFactory,
145-
'localeDate' => $this->localeDate,
143+
'emailSender' => $this->emailSender,
144+
'entityResource' => $this->entityResource,
145+
'entityCollection' => $this->entityCollection,
146+
'globalConfig' => $this->globalConfig,
147+
'identityContainer' => $this->identityContainerMock,
148+
'storeManager' => $this->storeManagerMock,
149+
'configValueFactory' => $this->configValueFactory,
150+
'localeDate' => $this->localeDate,
151+
'modifyStartFromDate' => $this->modifyStartFromDate
146152
]
147153
);
148154
}
@@ -177,7 +183,7 @@ public function testExecute($configValue, $collectionItems, $emailSendingResult)
177183

178184
$dateTime = new \DateTime();
179185
$nowDate = $dateTime->format('Y-m-d H:i:s');
180-
$fromDate = $dateTime->modify('-1 day')->format('Y-m-d H:i:s');
186+
$fromDate = $dateTime->modify($this->modifyStartFromDate)->format('Y-m-d H:i:s');
181187
$this->entityCollection
182188
->expects($this->at(2))
183189
->method('addFieldToFilter')

0 commit comments

Comments
 (0)