9
9
use Magento \Store \Model \ScopeInterface ;
10
10
11
11
/**
12
+ * Saves data from order to purchased links.
13
+ *
12
14
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13
15
*/
14
16
class SaveDownloadableOrderItemObserver implements ObserverInterface
@@ -92,9 +94,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
92
94
if ($ purchasedLink ->getId ()) {
93
95
return $ this ;
94
96
}
97
+ $ storeId = $ orderItem ->getOrder ()->getStoreId ();
98
+ $ orderStatusToEnableItem = $ this ->_scopeConfig ->getValue (
99
+ \Magento \Downloadable \Model \Link \Purchased \Item::XML_PATH_ORDER_ITEM_STATUS ,
100
+ ScopeInterface::SCOPE_STORE ,
101
+ $ storeId
102
+ );
95
103
if (!$ product ) {
96
104
$ product = $ this ->_createProductModel ()->setStoreId (
97
- $ orderItem -> getOrder ()-> getStoreId ()
105
+ $ storeId
98
106
)->load (
99
107
$ orderItem ->getProductId ()
100
108
);
@@ -150,6 +158,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
150
158
)->setNumberOfDownloadsBought (
151
159
$ numberOfDownloads
152
160
)->setStatus (
161
+ \Magento \Sales \Model \Order \Item::STATUS_PENDING == $ orderStatusToEnableItem ?
162
+ \Magento \Downloadable \Model \Link \Purchased \Item::LINK_STATUS_AVAILABLE :
153
163
\Magento \Downloadable \Model \Link \Purchased \Item::LINK_STATUS_PENDING
154
164
)->setCreatedAt (
155
165
$ orderItem ->getCreatedAt ()
@@ -165,6 +175,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
165
175
}
166
176
167
177
/**
178
+ * Create purchased model.
179
+ *
168
180
* @return \Magento\Downloadable\Model\Link\Purchased
169
181
*/
170
182
protected function _createPurchasedModel ()
@@ -173,6 +185,8 @@ protected function _createPurchasedModel()
173
185
}
174
186
175
187
/**
188
+ * Create product model.
189
+ *
176
190
* @return \Magento\Catalog\Model\Product
177
191
*/
178
192
protected function _createProductModel ()
@@ -181,6 +195,8 @@ protected function _createProductModel()
181
195
}
182
196
183
197
/**
198
+ * Create purchased item model.
199
+ *
184
200
* @return \Magento\Downloadable\Model\Link\Purchased\Item
185
201
*/
186
202
protected function _createPurchasedItemModel ()
@@ -189,6 +205,8 @@ protected function _createPurchasedItemModel()
189
205
}
190
206
191
207
/**
208
+ * Create items collection.
209
+ *
192
210
* @return \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\Collection
193
211
*/
194
212
protected function _createItemsCollection ()
0 commit comments