Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug report (verified): $downloadsLeft does not check for "Unlimited" downloads option #4

Open
romeof1980 opened this issue Nov 25, 2021 · 1 comment

Comments

@romeof1980
Copy link
Contributor

romeof1980 commented Nov 25, 2021

Prerequisites:
source: vendor/scandipwa/customer-downloadable-graphql/src/etc/di.xml

 <preference for="Magento\Downloadable\Controller\Download\Link"
                type="ScandiPWA\CustomerDownloadableGraphQl\Controller\Download\Link"/>

Class \ScandiPWA\CustomerDownloadableGraphQl\Controller\Download\Link line 93:

$downloadsLeft = $linkPurchasedItem->getNumberOfDownloadsBought() -
            $linkPurchasedItem->getNumberOfDownloadsUsed();

this checks only for "number" of downloads but does not check if "Unlimited" is selected in product's "downloadable information" section.
If we rely on "unlimited" it fails as when link expires.
See attachment: how is it possible to have "expired" if "Remaining Downloads" are set to "Unlimited"?

This happens because CLEARLY the scandi class takes another approach compared to the magento class it rewrites:
The magento class Magento\Downloadable\Controller\Download\Link on line 100 checks:

 if ($status == PurchasedLink::LINK_STATUS_AVAILABLE && ($downloadsLeft ||
            $linkPurchasedItem->getNumberOfDownloadsBought() == 0)
        ) 

ScandiPWA\CustomerDownloadableGraphQl\Controller\Download\Link checks instead

 if (($downloadsLeft || $linkPurchasedItem->getNumberOfDownloadsBought() === 0)) 

there is a HUGE difference here between == and === 0
basically it boils down to this.

because the value here (for various reason) could be a string if not a number in the original array (remember php would not throw an error when adding a string that can be converted to a number and would take care of it)

thanks

For the same reason see here how link is marked as expired even if "remaining downloads" shows "Unlimited left"
unlimited-expired

@romeof1980
Copy link
Contributor Author

romeof1980 commented Nov 25, 2021

I tested the hotfix and created a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant