I know that Commerce File does not allow anonymous users to purchase files but from a UI standpoint I want users to be able to download a file ONE TIME immediately after purchase REGARDLESS of whether or not they verify their email. Currently after purchasing a file, a customer must verify their email with a one-time login link, change their password, and then (if they're lucky) they figure out where their files are since there are no direct file download tokens yet or including in confirmation emails (see #1412252: Direct file download link). To me that's an unnecessary burden to place on customers.

To solve this (partially) I've added Commerce File fields to the order line item View at admin/structure/views/view/commerce_line_item_table/edit which at least gives users direct access to their files via a link to their order.

Next I created a new rule based on the "Control access to licensed file downloads" rule. My rule does a simple check to see if the file has ever been downloaded. If not it grants access to the file regardless of file access limitations. However it does not work because the action "ALLOW download of a licensed file" only allows the logged-in license holder to download the file. Thus defeating the purpose of the rule. Here's the view:

{ "rules_allow_first_time_anonymous_licensed_file_download" : {
    "LABEL" : "Allow first time Anonymous licensed file download",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "commerce_file" ],
    "REQUIRES" : [ "rules", "commerce_file" ],
    "ON" : [ "commerce_file_license_download" ],
    "IF" : [
      { "data_is_empty" : { "data" : [ "commerce-file-license:download-count" ] } }
    ],
    "DO" : [
      { "commerce_file_license_allow_download" : { "license" : [ "commerce-file-license" ] } }
    ]
  }
}

This would work if there was a rules action such as "ALLOW Anonymous download of a licensed file" or something similar.

Until that happens, how can I bypass or fool the commerce file license system with PHP code in my rule to allow a not-logged-in customer to download a file?

Thank you

Comments

bojanz’s picture

Status: Active » Closed (duplicate)