diff -Nuar a/vendor/magento/module-sales/Model/EmailSenderHandler.php b/vendor/magento/module-sales/Model/EmailSenderHandler.php
index 7c7005bf0da..a201c1285ae 100644
--- a/vendor/magento/module-sales/Model/EmailSenderHandler.php
+++ b/vendor/magento/module-sales/Model/EmailSenderHandler.php
@@ -5,7 +5,11 @@
*/
namespace Magento\Sales\Model;
+use Magento\Framework\App\Config\ValueFactory;
+use Magento\Framework\App\Config\ValueInterface;
+use Magento\Framework\App\ObjectManager;
use Magento\Sales\Model\Order\Email\Container\IdentityInterface;
+use Magento\Sales\Model\ResourceModel\Collection\AbstractCollection;
/**
* Sales emails sending
@@ -32,7 +36,7 @@ class EmailSenderHandler
/**
* Entity collection model.
*
- * @var \Magento\Sales\Model\ResourceModel\Collection\AbstractCollection
+ * @var AbstractCollection
*/
protected $entityCollection;
@@ -53,32 +57,50 @@ class EmailSenderHandler
*/
private $storeManager;
+ /**
+ * Config data factory
+ *
+ * @var ValueFactory
+ */
+ private $configValueFactory;
+
+ /**
+ * @var string
+ */
+ private $modifyStartFromDate;
+
/**
* @param \Magento\Sales\Model\Order\Email\Sender $emailSender
* @param \Magento\Sales\Model\ResourceModel\EntityAbstract $entityResource
- * @param \Magento\Sales\Model\ResourceModel\Collection\AbstractCollection $entityCollection
+ * @param AbstractCollection $entityCollection
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
* @param IdentityInterface|null $identityContainer
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @throws \InvalidArgumentException
+ * @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
+ * @param ValueFactory|null $configValueFactory
+ * @param string|null $modifyStartFromDate
*/
public function __construct(
\Magento\Sales\Model\Order\Email\Sender $emailSender,
\Magento\Sales\Model\ResourceModel\EntityAbstract $entityResource,
- \Magento\Sales\Model\ResourceModel\Collection\AbstractCollection $entityCollection,
+ AbstractCollection $entityCollection,
\Magento\Framework\App\Config\ScopeConfigInterface $globalConfig,
IdentityInterface $identityContainer = null,
- \Magento\Store\Model\StoreManagerInterface $storeManager = null
+ \Magento\Store\Model\StoreManagerInterface $storeManager = null,
+ ?ValueFactory $configValueFactory = null,
+ ?string $modifyStartFromDate = null
) {
$this->emailSender = $emailSender;
$this->entityResource = $entityResource;
$this->entityCollection = $entityCollection;
$this->globalConfig = $globalConfig;
- $this->identityContainer = $identityContainer ?: \Magento\Framework\App\ObjectManager::getInstance()
+ $this->identityContainer = $identityContainer ?: ObjectManager::getInstance()
->get(\Magento\Sales\Model\Order\Email\Container\NullIdentity::class);
- $this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()
+ $this->storeManager = $storeManager ?: ObjectManager::getInstance()
->get(\Magento\Store\Model\StoreManagerInterface::class);
+
+ $this->configValueFactory = $configValueFactory ?: ObjectManager::getInstance()->get(ValueFactory::class);
+ $this->modifyStartFromDate = $modifyStartFromDate ?: $this->modifyStartFromDate;
}
/**
@@ -90,6 +112,7 @@ class EmailSenderHandler
if ($this->globalConfig->getValue('sales_email/general/async_sending')) {
$this->entityCollection->addFieldToFilter('send_email', ['eq' => 1]);
$this->entityCollection->addFieldToFilter('email_sent', ['null' => true]);
+ $this->filterCollectionByStartFromDate($this->entityCollection);
$this->entityCollection->setPageSize(
$this->globalConfig->getValue('sales_email/general/sending_limit')
);
@@ -126,7 +149,7 @@ class EmailSenderHandler
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function getStores(
- \Magento\Sales\Model\ResourceModel\Collection\AbstractCollection $entityCollection
+ AbstractCollection $entityCollection
): array {
$stores = [];
@@ -140,4 +163,26 @@ class EmailSenderHandler
return $stores;
}
+
+ /**
+ * Filter collection by start from date
+ *
+ * @param AbstractCollection $collection
+ * @return void
+ */
+ private function filterCollectionByStartFromDate(AbstractCollection $collection): void
+ {
+ /** @var $configValue ValueInterface */
+ $configValue = $this->configValueFactory->create();
+ $configValue->load('sales_email/general/async_sending', 'path');
+
+ if ($configValue->getId()) {
+ $startFromDate = date(
+ 'Y-m-d H:i:s',
+ strtotime($configValue->getUpdatedAt() . ' ' . $this->modifyStartFromDate)
+ );
+
+ $collection->addFieldToFilter('created_at', ['from' => $startFromDate]);
+ }
+ }
}
diff -Nuar a/vendor/magento/module-sales/etc/di.xml b/vendor/magento/module-sales/etc/di.xml
index f6618c9884d..c514f757697 100644
--- a/vendor/magento/module-sales/etc/di.xml
+++ b/vendor/magento/module-sales/etc/di.xml
@@ -215,6 +215,11 @@
+
+
+ -1 day
+
+
Magento\Sales\Model\ResourceModel\Order\Grid