Hi there,
I can see from past issues that it's possible with the module to enable downloadable file purchasing for anonymous users. However, even though I've followed the official docs for the 7.x-2.x branch, I cannot do an anonymous checkout and be allowed to download the file.
Instead:
- I see an icon for the file type and the file name, but neither is linked
- users with appropriate permissions can download files from admin/commerce/licenses
I assume this is (my) user error, but I can't find out what the last step must be after examining permissions, documentation and configuration for the various modules.
Can anyone enlighten me?
Also, is the fact that all downloads of a given file use the same URL when private downloading is specified for the field worthy of a separate bug report?
-- b
RESOLUTION: Make sure that your site is configured to create new users on checkout. A user account must exist for the license to be assigned to, even though the user doesn't need to be logged into it on the checkout completion page.
Comments
Comment #1
bojanz CreditAttribution: bojanz commentedWe use our own url (file/%file/download), there's no bug there.
As for your issue, it is odd. You will need to debug theme_commerce_file_download_link(), log / output the value of $can_download, I'm guessing that it's FALSE in your case. Then debug commerce_file_can_download() and see which IF is returning FALSE in your case. That will allow us to track it down.
Comment #2
vwX CreditAttribution: vwX commentedBedlam, do you happen to have the media module enabled? If so then the file_entity module (media/file_entity) it comes with conflicts with the file_entity module. Why they have the same names, I don't know. Disable the one that comes with media and delete the directory, although you might want to make a copy of it in case media breaks.
Comment #3
bojanz CreditAttribution: bojanz commentedYes, file_entity needs to be the 2.x version, won't work otherwise.
Waiting for further feedback.
Comment #4
bojanz CreditAttribution: bojanz commentedNo further feedback provided. Nothing else to do.
Comment #5
bedlamEh. Sorry for not responding earlier—d.o still does not send me notifications for every issue I'm following.
Anyhow, just a data point since we were unable to proceed, but the media module was neither enabled nor even present.
-- b
Comment #6
bojanz CreditAttribution: bojanz commentedWhat did you do? Give up entirely? I provided debug instructions in #1.
Comment #7
K.MacKenzie CreditAttribution: K.MacKenzie commentedI am having this same issue. Currently stuck on it, will attempt to debug today.
Comment #8
K.MacKenzie CreditAttribution: K.MacKenzie commentedThe problem seems to be in CommerceLicenseFile.class.php.
Line 31:
$output = field_view_field('commerce_product', $product, 'commerce_file', $display);
Is outputing plain text rather than a link.
When I do a vardump I get this:
Comment #9
K.MacKenzie CreditAttribution: K.MacKenzie commentedComment #10
K.MacKenzie CreditAttribution: K.MacKenzie commentedThe problem is that ['#license'] is not being assigned, now I am just trying to figure out why.
Comment #11
K.MacKenzie CreditAttribution: K.MacKenzie commentedOK, I think I understand what is happening, but I am not sure the best way to fix it.
In CommerceLicenseFile.class.php around line 21 we have:
This comment leads me to believe that all access checks should be bypassed from this point forward, because if this code is being called then we already know that the user should be able to see the file access link.
Then this function calls $output = field_view_field('commerce_product', $product, 'commerce_file', $display);
and finally drupal_render();
Part of the problem is that for some reason there is no license assigned, this could be by design because we are dealing with an anonymous user (further digging my answer this question), so when drupal_render() passes the variables to theme_commerce_file_download_link() it goes through another access check via
if (empty($variables['license']))
which returns false, and blocks our access.This leads me to believe that either:
a) I have configured something wrong, and there SHOULD be a license variable present despite being an anonymous user.
or
b) There is a bug, and setting
'check_access' => FALSE
in the $display parameter doesn't work as intended.Comment #12
K.MacKenzie CreditAttribution: K.MacKenzie commentedOk. I found the root of the problem, for certain this time.
Line 395 of commerce_file.module
In our site configurations Drupal commerce doesn't create user accounts. It is not clear that commerce_file does not support this, in-fact it implies the opposite. Yet that comment line says it all.
Would be nice if it clearly stated in the documentation (or even the module description page) that...
"Create a new account for an anonymous order" rule MUST be enabled for checkout completion download for anonymous users to work. Licenses must be assigned to a user ID to be valid, therefor a user account must be created for the license to work (and the file to be downloadable) even if the user isn't logged into it.
Comment #13
bojanz CreditAttribution: bojanz commentedGreat debug work!
Yes, we rely on the rule that creates a new account, because at the end we need to know who the license belongs to.
If that rule doesn't run, then the license stays unassigned, which makes it basically useless.
Looks like you will need some custom code on your end to handle the download in that case.
I'd be happy to discuss changes to the module code. Let me know how I can help.
Comment #14
K.MacKenzie CreditAttribution: K.MacKenzie commentedYeah, I continued to dig deeper into the module to see if I should attempt to write a patch, create my own module, or simply change our configuration.
It seemed as though it was quite the can of worms, so I decided to just change our configuration so that users are created on checkout, but no welcome email is sent.
I may come back to this with a patch in the future. If I do, I will re-open the issue.
Thanks,