@@ -26,14 +26,14 @@ class EmailSenderHandler
26
26
/**
27
27
* Email sender model.
28
28
*
29
- * @var \Magento\Sales\Model\Order\Email\ Sender
29
+ * @var Sender
30
30
*/
31
31
protected $ emailSender ;
32
32
33
33
/**
34
34
* Entity resource model.
35
35
*
36
- * @var \Magento\Sales\Model\ResourceModel\ EntityAbstract
36
+ * @var EntityAbstract
37
37
*/
38
38
protected $ entityResource ;
39
39
@@ -47,7 +47,7 @@ class EmailSenderHandler
47
47
/**
48
48
* Global configuration storage.
49
49
*
50
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
50
+ * @var ScopeConfigInterface
51
51
*/
52
52
protected $ globalConfig ;
53
53
@@ -57,7 +57,7 @@ class EmailSenderHandler
57
57
private $ identityContainer ;
58
58
59
59
/**
60
- * @var \Magento\Store\Model\ StoreManagerInterface
60
+ * @var StoreManagerInterface
61
61
*/
62
62
private $ storeManager ;
63
63
@@ -73,11 +73,6 @@ class EmailSenderHandler
73
73
*/
74
74
private $ modifyStartFromDate ;
75
75
76
- /**
77
- * @var int
78
- */
79
- private int $ maxSendAttempts ;
80
-
81
76
/**
82
77
* @param Sender $emailSender
83
78
* @param EntityAbstract $entityResource
@@ -87,18 +82,16 @@ class EmailSenderHandler
87
82
* @param StoreManagerInterface|null $storeManager
88
83
* @param ValueFactory|null $configValueFactory
89
84
* @param string|null $modifyStartFromDate
90
- * @param int $maxSendAttempts
91
85
*/
92
86
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 ,
102
95
) {
103
96
$ this ->emailSender = $ emailSender ;
104
97
$ this ->entityResource = $ entityResource ;
@@ -108,11 +101,10 @@ public function __construct(
108
101
$ this ->identityContainer = $ identityContainer ?: ObjectManager::getInstance ()
109
102
->get (\Magento \Sales \Model \Order \Email \Container \NullIdentity::class);
110
103
$ this ->storeManager = $ storeManager ?: ObjectManager::getInstance ()
111
- ->get (\ Magento \ Store \ Model \ StoreManagerInterface::class);
104
+ ->get (StoreManagerInterface::class);
112
105
113
106
$ this ->configValueFactory = $ configValueFactory ?: ObjectManager::getInstance ()->get (ValueFactory::class);
114
107
$ this ->modifyStartFromDate = $ modifyStartFromDate ?: $ this ->modifyStartFromDate ;
115
- $ this ->maxSendAttempts = $ maxSendAttempts ?? 3 ;
116
108
}
117
109
118
110
/**
@@ -139,6 +131,8 @@ public function sendEmails()
139
131
/** @var \Magento\Store\Api\Data\StoreInterface[] $stores */
140
132
$ stores = $ this ->getStores (clone $ this ->entityCollection );
141
133
134
+ $ maxSendAttempts = $ this ->globalConfig ->getValue ('sales_email/general/async_sending_attempts ' );
135
+
142
136
/** @var \Magento\Store\Model\Store $store */
143
137
foreach ($ stores as $ store ) {
144
138
$ this ->identityContainer ->setStore ($ store );
@@ -150,7 +144,7 @@ public function sendEmails()
150
144
151
145
/** @var \Magento\Sales\Model\AbstractModel $item */
152
146
foreach ($ entityCollection ->getItems () as $ item ) {
153
- $ sendAttempts = $ item ->getEmailSent () ?? -$ this -> maxSendAttempts ;
147
+ $ sendAttempts = $ item ->getEmailSent () ?? -$ maxSendAttempts ;
154
148
$ isEmailSent = $ this ->emailSender ->send ($ item , true );
155
149
156
150
if ($ isEmailSent ) {
@@ -183,7 +177,7 @@ private function getStores(
183
177
$ entityCollection ->addAttributeToSelect ('store_id ' )->getSelect ()->group ('store_id ' );
184
178
/** @var \Magento\Sales\Model\EntityInterface $item */
185
179
foreach ($ entityCollection ->getItems () as $ item ) {
186
- /** @var \Magento\Store\Model\ StoreManagerInterface $store */
180
+ /** @var StoreManagerInterface $store */
187
181
$ store = $ this ->storeManager ->getStore ($ item ->getStoreId ());
188
182
$ stores [$ item ->getStoreId ()] = $ store ;
189
183
}
0 commit comments