On a product page, I want the following:

If product price <= $0 or the logged in user has a certain role, the Add to Cart button is replaced by a "Download Now" button that links directly to the attached file download for that particular product.

I know how to write the if statement for those conditions in my node--product.tpl.php template, but how can I print the direct link to an attached File Download in my node--product.tpl.php?

Additionally, I'd like to have the Add to Cart/Direct Download button in a block rather than in the node area. I can make a block containing the Add to Cart form with Views and display it on the proper product pages no problem, but again, I'd like the Add to Cart button to turn to a direct download link based on those 2 conditions.

Has anyone ever done this? I feel like it's a normal thing with a lot of the WordPress ecommerce solutions I've used.

Comments

haysuess’s picture

Well, I've figured out the best workflow for this in case anyone else wants to do it. It was easier than I first thought.

  • Add a "File" field to the Product content type (make it unlimited if you want to have multiple file download options per product)
  • Upload your file download(s) to this field
  • Add "File Download" under "Features" and you'll find the file you uploaded in the autofill

Now you can print the add to cart form or a direct download link in your template file or a view, based on some if/then logic.

I'm also using the /s3fs module with my product file downloads directory set to "s3://". I can then attach a file to a product as a Feature from ANY subfolder in my Amazon S3 bucket. Perfect :)

TR’s picture

Status: Active » Fixed

Yes, if you're not going to charge for the file, and don't need to restrict number of downloads, limit the time period for the download, etc., then a file field is the best way. If you really want to print the uc_file link, then you can look into the uc_file_user_downloads() function to see how that data is stored in the DB. However, you need to be careful to perform the checks in that function to make sure the user should have access to the file. With uc_file, permission to download files is user-based, not node-based - every user will have a different link for the same file on the same product node.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

davemurphy’s picture

hi Haysuess

you said above:
"Now you can print the add to cart form or a direct download link in your template file or a view, based on some if/then logic."

can you please explain how you did this.
I have a product with a file download added to it under Features.
I need to present the product description in another view with a direct link to the associated downloadable file.
Any ideas on how I would automatically construct the link (the client has hundreds of products)?
e.g. using tokens

rgds Dave