Skip to content

Commit

Permalink
ENGCOM-4685: Bug fix for #21753 (2.3-develop) #22073
Browse files Browse the repository at this point in the history
  • Loading branch information
sidolov authored Apr 15, 2019
2 parents c47de20 + d36ca79 commit 6d6918e
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Store\Model\ScopeInterface;

/**
* Saves data from order to purchased links.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SaveDownloadableOrderItemObserver implements ObserverInterface
Expand Down Expand Up @@ -92,9 +94,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
if ($purchasedLink->getId()) {
return $this;
}
$storeId = $orderItem->getOrder()->getStoreId();
$orderStatusToEnableItem = $this->_scopeConfig->getValue(
\Magento\Downloadable\Model\Link\Purchased\Item::XML_PATH_ORDER_ITEM_STATUS,
ScopeInterface::SCOPE_STORE,
$storeId
);
if (!$product) {
$product = $this->_createProductModel()->setStoreId(
$orderItem->getOrder()->getStoreId()
$storeId
)->load(
$orderItem->getProductId()
);
Expand Down Expand Up @@ -150,6 +158,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
)->setNumberOfDownloadsBought(
$numberOfDownloads
)->setStatus(
\Magento\Sales\Model\Order\Item::STATUS_PENDING == $orderStatusToEnableItem ?
\Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE :
\Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING
)->setCreatedAt(
$orderItem->getCreatedAt()
Expand All @@ -165,6 +175,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
}

/**
* Create purchased model.
*
* @return \Magento\Downloadable\Model\Link\Purchased
*/
protected function _createPurchasedModel()
Expand All @@ -173,6 +185,8 @@ protected function _createPurchasedModel()
}

/**
* Create product model.
*
* @return \Magento\Catalog\Model\Product
*/
protected function _createProductModel()
Expand All @@ -181,6 +195,8 @@ protected function _createProductModel()
}

/**
* Create purchased item model.
*
* @return \Magento\Downloadable\Model\Link\Purchased\Item
*/
protected function _createPurchasedItemModel()
Expand All @@ -189,6 +205,8 @@ protected function _createPurchasedItemModel()
}

/**
* Create items collection.
*
* @return \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\Collection
*/
protected function _createItemsCollection()
Expand Down

0 comments on commit 6d6918e

Please sign in to comment.