Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there any way to add a token to an email sent by rules with a link to download the licensed file? Or even if there is another way using php or something to produce a link to download the licensed files from an email.
Any ideas here would be great!
Thanks
Comment | File | Size | Author |
---|---|---|---|
#7 | Capture.PNG | 13.2 KB | deggertsen |
#5 | 2065337-remove-unneeded-check.patch | 599 bytes | bojanz |
Comments
Comment #1
bojanz CreditAttribution: bojanz commented[commerce-license:access-details] should do the trick, try it.
Comment #2
deggertsen CreditAttribution: deggertsen commentedYes, I think that's the token I needed. However, right now it's not linking to anything, it's just giving the name of the licensed file. I think this is because of my problem in #2066109: Disable SQL rewriting for the Files view. Assuming that is the case we can go ahead and close this issue.
Thanks!
Comment #3
bojanz CreditAttribution: bojanz commentedI'm not convinced the issues are related.
I think the access limits are checked for the current user, which is not the same as the license owner at the point when the rule is invoked.
I guess we should disable the access limit check for the token. I will give it some more thought after dinner.
Comment #4
deggertsen CreditAttribution: deggertsen commentedYes, I was just coming back to this issue to confirm exactly what you said here. Unfortunately it simply states the file name without linking it to download the actual file. Seems to me that in most cases where this token is used access limit check should be disabled. That would work for me at least. I could see in some cases where people would want or need that to count towards their access limit though...
Comment #5
bojanz CreditAttribution: bojanz commentedCan you try this patch?
EDIT: And it might also make sense to show the links without the icons. What do you think is preferable?
EDIT2: Committed the patch in any case, since it makes sense.
Comment #6
deggertsen CreditAttribution: deggertsen commentedTried it, but there is still no link, it just has the file icon and the name of the file. It doesn't link to anything though.
I've attached a screenshot of part of the email just to help with the visual.
Comment #7
deggertsen CreditAttribution: deggertsen commentedOops, here's the screenshot.
Comment #8
bojanz CreditAttribution: bojanz commentedCan you export your rule, or describe your setup? I have trouble reproducing.
Comment #9
deggertsen CreditAttribution: deggertsen commentedHere is my rule export (personal site data removed):
Notice this is on the event of commerce_license_insert.
Thanks for looking at this.
Comment #10
bojanz CreditAttribution: bojanz commentedDid you manage to find a workaround for this?
I tried to finally debug this on the plane, reproduced it, but didn't get anywhere on determining the cause (though it seems that the bug is on the commerce_file side, no idea why it occurs).
Comment #11
deggertsen CreditAttribution: deggertsen commentedUnfortunately I did not find a workaround. All I am doing now in the email that goes out is directing them to their "Files" page in their profile so that they can then click the link to download their purchased files. You would think that wouldn't be a big deal, but we get a significant amount of email from people still asking how they download their purchased files. It would be nice if this worked, but like you I have not been able to figure it out yet.
Comment #12
Daniel Wentsch CreditAttribution: Daniel Wentsch commented*Bump*
It's been a while, thought I'd ask if somebody has made any progress on this? It does not seem to be such an uncommon requirement and I didn't find a solution yet.
My specific use case is that I'd like to allow anonymous checkout for file purchases.
Comment #13
deggertsen CreditAttribution: deggertsen commentedNope, I'd still love to see this functionality, but I don't have any idea how to go about getting it to work and it's not high enough priority for us to pay someone else the big bucks to figure it out. Still in the same situation as I stated in #11.
Comment #14
torgosPizzaIf it helps anyone I handled this in the Checkout page itself (nothing emailed) by creating a custom checkout pane. I basically copied the one that comes with Commerce License and added a loop for all licenses in an order, and showing those files if a license exists.
Here is some sample code, it should be correct but I took out some of our specific stuff so make sure you test it (and check my punctuation). To use it, create a custom module (in this example it's called MYMODULE.module) and then create a directory off the main module directory called "includes". Inside the includes/ directory create a file called commerce_checkout.checkout_pane.inc, and add the code below. Hack it to your tastes.
We don't really have a need for download links included in an email receipt but if this is something I'm able to drum up, I will post it here. Hopefully this helps someone who wants similar functionality, though.
Comment #15
nedjoAn issue to consider is that a download link in an email will potentially produce an access denied result in the case that a user isn't already logged in.
Comment #16
torgosPizzaThat's true. In our experience (especially if a user purchases dozens of products, which does happen on our site) it's better to just provide links to the product itself and include a "Download" link somewhere on that page if a user has purchased it. That is a field handler I'm working on for the Commerce File module - a "purchased links" view that could be added to a Panels pane etc.
Comment #17
jkdev CreditAttribution: jkdev commentedThe Reason you are not seeing the file name as link to download has something to do with this:
look at this file:
commerce_file.module
at this function:
theme_commerce_file_download_link
the
$can_download
variable apparently set to false. so this is a label rather than a link with token.Comment #18
upunkt CreditAttribution: upunkt commentedAny update on this?
Actually, I'm not even seeing the unlinked text like @deggertsen. The [commerce-license:access-details] is converted to either
- nothing (anonymous user, logged in via Login Toboggan and given a role with full file access) or
- n.v. (User 1)
Download from the Checkout-complete view works, though.
To get somewhere I tried to send the token on the event "Commerce Order is viewed" and tried various mail mechanisms, Drupal's own and Commerce Email with and without Variable Email. No difference sending as HTML or Text. The license is active, sure.
I've tried to use OP's rule from #9, and that made no difference either.
I've been testing with the latest stable versions of Commerce File (7.x-2.0-beta3) and Commerce License (7.x-1.3) and their latest dev-versions also.
As I do not find any official documentation about [commerce-license:access-details] I wonder whether there might be certain conditions to be met before this token can be converted. Please, @bojanz, could you explain what makes this token usable?
Thanks a lot in advance.
EDIT:
Other than the token-suggestions imply, some of the tokens need to be prefixed with a
site
, eg.[site:current-user:field_mycustomfield]
.Note the underscore in field_mycustomfield. This technique doesn't help with the access details, though.
Comment #19
upunkt CreditAttribution: upunkt commentedI got it.
When configuring your rule for sending out e-mail you must react on an event from the Commerce License-block. Since all my other e-mails have their origin in a Commerce Order-event I tried adding the token
[commerce-license:access-details]
just there. This fails. Configure an extra rule.For completeness, this is my setup.
Rules 7x.-2.9
Commerce Email 7.x-2.x-dev
Mime Mail 7.x-1.0-beta4
Variable Email 7.x-1.0-alpha1+3-dev
Commerce 7.x-1.13
Commerce File 7.x-2.0-beta3+3-dev
Commerce License 7.x-1.3+12-dev
Puh, many dev-versions. But I'm not willing to switch back to non-dev since everything works. Still, I encourage you to try with stable ones first.