@@ -26,14 +26,14 @@ class EmailSenderHandler
2626 /**
2727 * Email sender model.
2828 *
29- * @var \Magento\Sales\Model\Order\Email\ Sender
29+ * @var Sender
3030 */
3131 protected $ emailSender ;
3232
3333 /**
3434 * Entity resource model.
3535 *
36- * @var \Magento\Sales\Model\ResourceModel\ EntityAbstract
36+ * @var EntityAbstract
3737 */
3838 protected $ entityResource ;
3939
@@ -47,7 +47,7 @@ class EmailSenderHandler
4747 /**
4848 * Global configuration storage.
4949 *
50- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
50+ * @var ScopeConfigInterface
5151 */
5252 protected $ globalConfig ;
5353
@@ -57,7 +57,7 @@ class EmailSenderHandler
5757 private $ identityContainer ;
5858
5959 /**
60- * @var \Magento\Store\Model\ StoreManagerInterface
60+ * @var StoreManagerInterface
6161 */
6262 private $ storeManager ;
6363
@@ -73,11 +73,6 @@ class EmailSenderHandler
7373 */
7474 private $ modifyStartFromDate ;
7575
76- /**
77- * @var int
78- */
79- private int $ maxSendAttempts ;
80-
8176 /**
8277 * @param Sender $emailSender
8378 * @param EntityAbstract $entityResource
@@ -87,18 +82,16 @@ class EmailSenderHandler
8782 * @param StoreManagerInterface|null $storeManager
8883 * @param ValueFactory|null $configValueFactory
8984 * @param string|null $modifyStartFromDate
90- * @param int $maxSendAttempts
9185 */
9286 public function __construct (
93- \Magento \Sales \Model \Order \Email \Sender $ emailSender ,
94- \Magento \Sales \Model \ResourceModel \EntityAbstract $ entityResource ,
95- AbstractCollection $ entityCollection ,
96- \Magento \Framework \App \Config \ScopeConfigInterface $ globalConfig ,
97- IdentityInterface $ identityContainer = null ,
98- \Magento \Store \Model \StoreManagerInterface $ storeManager = null ,
99- ?ValueFactory $ configValueFactory = null ,
100- ?string $ modifyStartFromDate = null ,
101- int $ maxSendAttempts = null
87+ Sender $ emailSender ,
88+ EntityAbstract $ entityResource ,
89+ AbstractCollection $ entityCollection ,
90+ ScopeConfigInterface $ globalConfig ,
91+ IdentityInterface $ identityContainer = null ,
92+ StoreManagerInterface $ storeManager = null ,
93+ ?ValueFactory $ configValueFactory = null ,
94+ ?string $ modifyStartFromDate = null ,
10295 ) {
10396 $ this ->emailSender = $ emailSender ;
10497 $ this ->entityResource = $ entityResource ;
@@ -108,11 +101,10 @@ public function __construct(
108101 $ this ->identityContainer = $ identityContainer ?: ObjectManager::getInstance ()
109102 ->get (\Magento \Sales \Model \Order \Email \Container \NullIdentity::class);
110103 $ this ->storeManager = $ storeManager ?: ObjectManager::getInstance ()
111- ->get (\ Magento \ Store \ Model \ StoreManagerInterface::class);
104+ ->get (StoreManagerInterface::class);
112105
113106 $ this ->configValueFactory = $ configValueFactory ?: ObjectManager::getInstance ()->get (ValueFactory::class);
114107 $ this ->modifyStartFromDate = $ modifyStartFromDate ?: $ this ->modifyStartFromDate ;
115- $ this ->maxSendAttempts = $ maxSendAttempts ?? 3 ;
116108 }
117109
118110 /**
@@ -139,6 +131,8 @@ public function sendEmails()
139131 /** @var \Magento\Store\Api\Data\StoreInterface[] $stores */
140132 $ stores = $ this ->getStores (clone $ this ->entityCollection );
141133
134+ $ maxSendAttempts = $ this ->globalConfig ->getValue ('sales_email/general/async_sending_attempts ' );
135+
142136 /** @var \Magento\Store\Model\Store $store */
143137 foreach ($ stores as $ store ) {
144138 $ this ->identityContainer ->setStore ($ store );
@@ -150,7 +144,7 @@ public function sendEmails()
150144
151145 /** @var \Magento\Sales\Model\AbstractModel $item */
152146 foreach ($ entityCollection ->getItems () as $ item ) {
153- $ sendAttempts = $ item ->getEmailSent () ?? -$ this -> maxSendAttempts ;
147+ $ sendAttempts = $ item ->getEmailSent () ?? -$ maxSendAttempts ;
154148 $ isEmailSent = $ this ->emailSender ->send ($ item , true );
155149
156150 if ($ isEmailSent ) {
@@ -183,7 +177,7 @@ private function getStores(
183177 $ entityCollection ->addAttributeToSelect ('store_id ' )->getSelect ()->group ('store_id ' );
184178 /** @var \Magento\Sales\Model\EntityInterface $item */
185179 foreach ($ entityCollection ->getItems () as $ item ) {
186- /** @var \Magento\Store\Model\ StoreManagerInterface $store */
180+ /** @var StoreManagerInterface $store */
187181 $ store = $ this ->storeManager ->getStore ($ item ->getStoreId ());
188182 $ stores [$ item ->getStoreId ()] = $ store ;
189183 }
0 commit comments