22 return $this->_objectManager->get(\
Magento\Customer\Model\Session::class);
40 $linkPurchasedItem = $this->_objectManager->create(
41 \
Magento\Downloadable\Model\
Link\Purchased\Item::class
46 if (!$linkPurchasedItem->getId()) {
47 $this->messageManager->addNotice(
__(
"We can't find the link you requested."));
48 return $this->
_redirect(
'*/customer/products');
50 if (!$this->_objectManager->get(\
Magento\Downloadable\Helper\Data::class)->getIsShareable($linkPurchasedItem)) {
54 $product = $this->_objectManager->create(
55 \
Magento\Catalog\Model\Product::class
57 $linkPurchasedItem->getProductId()
61 'Please sign in to download your product or purchase <a href="%1">%2</a>.',
66 $notice =
__(
'Please sign in to download your product.');
68 $this->messageManager->addNotice($notice);
71 $this->_objectManager->create(
72 \
Magento\Framework\UrlInterface::class
74 'downloadable/customer/products/',
81 $linkPurchased = $this->_objectManager->create(
82 \
Magento\Downloadable\Model\Link\Purchased::class
84 $linkPurchasedItem->getPurchasedId()
86 if ($linkPurchased->getCustomerId() !=
$customerId) {
87 $this->messageManager->addNotice(
__(
"We can't find the link you requested."));
88 return $this->
_redirect(
'*/customer/products');
91 $downloadsLeft = $linkPurchasedItem->getNumberOfDownloadsBought() -
92 $linkPurchasedItem->getNumberOfDownloadsUsed();
94 $status = $linkPurchasedItem->getStatus();
95 if (
$status == PurchasedLink::LINK_STATUS_AVAILABLE && ($downloadsLeft ||
96 $linkPurchasedItem->getNumberOfDownloadsBought() == 0)
100 if ($linkPurchasedItem->getLinkType() == DownloadHelper::LINK_TYPE_URL) {
101 $resource = $linkPurchasedItem->getLinkUrl();
102 $resourceType = DownloadHelper::LINK_TYPE_URL;
103 }
elseif ($linkPurchasedItem->getLinkType() == DownloadHelper::LINK_TYPE_FILE) {
105 \
Magento\Downloadable\Helper\File::class
108 $linkPurchasedItem->getLinkFile()
110 $resourceType = DownloadHelper::LINK_TYPE_FILE;
113 $this->_processDownload(
$resource, $resourceType);
114 $linkPurchasedItem->setNumberOfDownloadsUsed($linkPurchasedItem->getNumberOfDownloadsUsed() + 1);
116 if ($linkPurchasedItem->getNumberOfDownloadsBought() != 0 && !($downloadsLeft - 1)) {
117 $linkPurchasedItem->setStatus(PurchasedLink::LINK_STATUS_EXPIRED);
119 $linkPurchasedItem->save();
121 }
catch (\Exception $e) {
122 $this->messageManager->addError(
__(
'Something went wrong while getting the requested content.'));
125 $this->messageManager->addNotice(
__(
'The link has expired.'));
126 }
elseif (
$status == PurchasedLink::LINK_STATUS_PENDING ||
$status == PurchasedLink::LINK_STATUS_PAYMENT_REVIEW
128 $this->messageManager->addNotice(
__(
'The link is not available.'));
130 $this->messageManager->addError(
__(
'Something went wrong while getting the requested content.'));
132 return $this->
_redirect(
'*/customer/products');
_redirect($path, $arguments=[])
elseif(isset( $params[ 'redirect_parent']))