Skip to content

Commit d36ca79

Browse files
ENGCOM-4685: Bug fix for #21753 (2.3-develop) #22073
- Merge Pull Request #22073 from crankycyclops/magento2:2.3-21753-fix - Merged commits: 1. 6076fdc 2. d32da36 3. 2c16697 4. 5410e07 5. d189b69 6. 460c4f3
2 parents abd84ea + 460c4f3 commit d36ca79

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

app/code/Magento/Downloadable/Observer/SaveDownloadableOrderItemObserver.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Store\Model\ScopeInterface;
1010

1111
/**
12+
* Saves data from order to purchased links.
13+
*
1214
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1315
*/
1416
class SaveDownloadableOrderItemObserver implements ObserverInterface
@@ -92,9 +94,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
9294
if ($purchasedLink->getId()) {
9395
return $this;
9496
}
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+
);
95103
if (!$product) {
96104
$product = $this->_createProductModel()->setStoreId(
97-
$orderItem->getOrder()->getStoreId()
105+
$storeId
98106
)->load(
99107
$orderItem->getProductId()
100108
);
@@ -150,6 +158,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
150158
)->setNumberOfDownloadsBought(
151159
$numberOfDownloads
152160
)->setStatus(
161+
\Magento\Sales\Model\Order\Item::STATUS_PENDING == $orderStatusToEnableItem ?
162+
\Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE :
153163
\Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING
154164
)->setCreatedAt(
155165
$orderItem->getCreatedAt()
@@ -165,6 +175,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
165175
}
166176

167177
/**
178+
* Create purchased model.
179+
*
168180
* @return \Magento\Downloadable\Model\Link\Purchased
169181
*/
170182
protected function _createPurchasedModel()
@@ -173,6 +185,8 @@ protected function _createPurchasedModel()
173185
}
174186

175187
/**
188+
* Create product model.
189+
*
176190
* @return \Magento\Catalog\Model\Product
177191
*/
178192
protected function _createProductModel()
@@ -181,6 +195,8 @@ protected function _createProductModel()
181195
}
182196

183197
/**
198+
* Create purchased item model.
199+
*
184200
* @return \Magento\Downloadable\Model\Link\Purchased\Item
185201
*/
186202
protected function _createPurchasedItemModel()
@@ -189,6 +205,8 @@ protected function _createPurchasedItemModel()
189205
}
190206

191207
/**
208+
* Create items collection.
209+
*
192210
* @return \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\Collection
193211
*/
194212
protected function _createItemsCollection()

0 commit comments

Comments
 (0)