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

bojanz’s picture

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?

We 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.

vwX’s picture

Bedlam, 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.

bojanz’s picture

Status: Active » Postponed (maintainer needs more info)

Yes, file_entity needs to be the 2.x version, won't work otherwise.

Waiting for further feedback.

bojanz’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (works as designed)

No further feedback provided. Nothing else to do.

bedlam’s picture

Eh. 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

bojanz’s picture

What did you do? Give up entirely? I provided debug instructions in #1.

K.MacKenzie’s picture

I am having this same issue. Currently stuck on it, will attempt to debug today.

K.MacKenzie’s picture

The 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:

Array
(
    [#theme] => field
    [#weight] => 0
    [#title] => Files
    [#access] => 1
    [#label_display] => hidden
    [#view_mode] => _custom_display
    [#language] => und
    [#field_name] => commerce_file
    [#field_type] => file
    [#field_translatable] => 0
    [#entity_type] => commerce_product
    [#bundle] => product
    [#object] => stdClass Object
        (
            [revision_id] => 11
            [sku] => MYFILESKU
            [title] => MYFILENAME
            [revision_uid] => 1
            [status] => 1
            [log] => 
            [revision_timestamp] => 1386380997
            [data] => 
            [product_id] => 1
            [type] => product
            [language] => und
            [uid] => 1
            [created] => 1383333408
            [changed] => 1386380997
            [commerce_price] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [amount] => 30000
                                    [currency_code] => CAD
                                    [data] => Array
                                        (
                                            [components] => Array
                                                (
                                                )

                                        )

                                )

                        )

                )

            [field_sales_taxes_ca] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => 14
                                    [revision_id] => 140
                                )

                        )

                )

            [commerce_license_type] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => file
                                )

                        )

                )

            [commerce_license_duration] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => 2592000
                                )

                        )

                )

            [commerce_file] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [fid] => 122
                                    [display] => 1
                                    [description] => 
                                    [uid] => 1
                                    [filename] => FILENAME.pdf
                                    [uri] => private://FILENAME.pdf
                                    [filemime] => application/pdf
                                    [filesize] => 0
                                    [status] => 1
                                    [timestamp] => 1386380997
                                    [rdf_mapping] => Array
                                        (
                                        )

                                )

                        )

                )

            [rdf_mapping] => Array
                (
                )

        )

    [#items] => Array
        (
            [0] => Array
                (
                    [fid] => 122
                    [display] => 1
                    [description] => 
                    [uid] => 1
                    [filename] => FILENAME.pdf
                    [uri] => private://FILENAME.pdf
                    [filemime] => application/pdf
                    [filesize] => 0
                    [status] => 1
                    [timestamp] => 1386380997
                    [rdf_mapping] => Array
                        (
                        )

                )

        )

    [#formatter] => commerce_file
    [0] => Array
        (
            [#theme] => commerce_file_download_link
            [#file] => stdClass Object
                (
                    [fid] => 122
                    [display] => 1
                    [description] => 
                    [uid] => 1
                    [filename] => FILENAME.pdf
                    [uri] => private://FILENAME.pdf
                    [filemime] => application/pdf
                    [filesize] => 0
                    [status] => 1
                    [timestamp] => 1386380997
                    [rdf_mapping] => Array
                        (
                        )

                )

            [#license] => 
            [#icon] => 
        )

)
K.MacKenzie’s picture

Status: Closed (works as designed) » Active
K.MacKenzie’s picture

The problem is that ['#license'] is not being assigned, now I am just trying to figure out why.

K.MacKenzie’s picture

OK, 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:

    $display = array(
      'label' => 'hidden',
      'type' => 'commerce_file',
      'settings' => array(
        // The access check confirms that the product has a license.
        // Since we're calling this formatter from a license, there is no
        // point in performing that check.
        'check_access' => FALSE,
      ),
    );

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.

K.MacKenzie’s picture

Ok. I found the root of the problem, for certain this time.

Line 395 of commerce_file.module

  // Ignore anonymous users, they can't have licenses.
  if (empty($account->uid)) {
    return FALSE;
  }

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.

bojanz’s picture

Great 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.

K.MacKenzie’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

Yeah, 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,