Skip to content

Commit

Permalink
Merge pull request #1 from riha112/2270
Browse files Browse the repository at this point in the history
#2270 - Hides download link if unavailable
  • Loading branch information
alfredsgenkins authored Mar 15, 2021
2 parents cadd4ee + 40c4ceb commit 87aba7d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Model/Resolver/CustomerDownloadableProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\UrlInterface;
use Magento\GraphQl\Model\Query\ContextInterface;
use Magento\Sales\Model\Order;

/**
*
* Returns available downloadable products for customer
*/
class CustomerDownloadableProducts implements ResolverInterface
{
const DOWNLOADABLE_STATUES = [
'available',
Order::STATE_COMPLETE
];

/**
* @var GetPurchasedDownloadableProducts
*/
Expand Down Expand Up @@ -76,16 +82,22 @@ public function resolve(
$remainingDownloads = __('Unlimited');
}

/* Generates download url only if customer has any available downloads left or order is accepted */
$downloadUrl = null;
if ($remainingDownloads != '0' && in_array($purchasedProduct['status'], self::DOWNLOADABLE_STATUES)) {
$downloadUrl = $this->urlBuilder->getUrl(
'downloadable/download/link',
['id' => $purchasedProduct['link_hash'], '_secure' => true]
);
}

$productsData[] = [
'order_increment_id' => $purchasedProduct['order_increment_id'],
'date' => $purchasedProduct['created_at'],
'status' => $purchasedProduct['status'],
'title' => $purchasedProduct['product_name'],
'link_title' => $purchasedProduct['link_title'],
'download_url' => $this->urlBuilder->getUrl(
'downloadable/download/link',
['id' => $purchasedProduct['link_hash'], '_secure' => true]
),
'download_url' => $downloadUrl,
'remaining_downloads' => $remainingDownloads
];
}
Expand Down

0 comments on commit 87aba7d

Please sign in to comment.