Zen Cart Logo
Forums / Zen Cart Code Suggestions / Remote downloads - for Amazon S3 or other

Remote downloads - for Amazon S3 or other

Views: 372

Results 1 to 20 of 31
2 Feb 2011, 2:41 AM
#1
mcnewton avatar

mcnewton

New Zenner

Join Date:
Jan 2011
Location:
Leicestershire, UK
Posts:
5
Plugin Contributions:
0

Remote downloads - for Amazon S3 or other

**DOWNLOAD LINK:
http://www.zen-cart.com/downloads.php?do=file&id=1352
**

Hi,

I've recently started looking after a Zen Cart store for a small publishing company, and they wanted the ability to sell video downloads of their DVDs, and sell watermarked PDFs. Using Amazon S3 looked like a reasonable way to begin with for the rather large videos, but I couldn't find any way of doing the right redirect in Zen Cart. Also, it could handle plain PDFs, but not process them to add a watermark with the customer's name, etc.

I've therefore written a small patch (to 1.3.9h) that allows a download to run a script rather than serve the file to the customer. This makes it really easy to do both the above. The patch is about 30 changed lines, and 50 new, plus a 50-line "plug-and-play" example of how to do downloads from Amazon S3.

It works by including scripts from a "download script" directory at download time that can do a web redirect. To tell Zen Cart to download via a script rather than a static file, you put for example "script:amazons3.php" in the filename box.

At download time it includes the script, which can then do an HTTP redirect to wherever necessary. The S3 one encodes up the requested filename with an expiry date a few seconds into the future, so the download link can't be shared with other people, and then redirects to the Amazon URL. For the PDF watermarks I use a different script that encodes the customer name from the database on to the URL, with a crypto signature, and then redirects to another server to process the PDF.

Once a script is in place it can be given different options to process from the admin interface. For example, one download attribute might have "script:amazons3.php:episode1.m4v" and another might have "script:amazons3.php:episode2.m4v".

The only problem I've got now is trying to work out where to submit the patch (sorry, I get very confused with web forums!) I've put it here if anyone would like to review: dl.newtoncomputing.co.uk/downloadscripts.patch. It applies cleanly to the latest 1.3.9h zip: cd into the zen cart diretory and do 'patch -p1 < ../downloadscripts.patch' to apply.

If I should send it somewhere else or submit this some other way then please let me know. :-) Hope this helps someone!

Cheers,

Matthew

2 Feb 2011, 2:58 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Remote downloads - for Amazon S3 or other

You need to package it up in the correct tree structure as ZenCart is and allow for overrides if applicable or in a install readme make it plainly evident thet this will alter a file and what it is.

Include a proper license with it

Go here and see the submit file link at the top right

http://www.zen-cart.com/index.php?main_page=index&cPath=40

3 Feb 2011, 1:36 AM
#3
mcnewton avatar

mcnewton

New Zenner

Join Date:
Jan 2011
Location:
Leicestershire, UK
Posts:
5
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Hi,

OK, thanks for the pointer! I will hopefully get time to sort out a zip file & upload over the next few days.

Thanks,

Matthew

5 Jan 2012, 9:59 PM
#4
vooboo13 avatar

vooboo13

New Zenner

Join Date:
Dec 2009
Posts:
55
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Were you ever able to package this up? I'm very interested in this.

6 Jan 2012, 1:45 PM
#5
mcnewton avatar

mcnewton

New Zenner

Join Date:
Jan 2011
Location:
Leicestershire, UK
Posts:
5
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Hi vooboo13,

I haven't got around to creating a zip archive with this in yet, sorry. The patch given above should work if you can apply it.

I'll try and find time to have another look at it over the next couple of weeks or so. It's been working so well I'd almost forgotten about it... :)

Cheers,

Matthew

12 Jan 2012, 9:34 PM
#6
mcnewton avatar

mcnewton

New Zenner

Join Date:
Jan 2011
Location:
Leicestershire, UK
Posts:
5
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Hi,

I've packaged it up (for v1.3.9h) and submitted it to the contributions area. It's called 'Download-Scripts'. Available here: http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=2052

Hopefully the installation will be self-explanatory, but as I haven't tested this on anyone else's shop yet there may be something I've missed. Let me know if the instructions aren't clear enough!

You'll need to edit the amazons3.php script to set your key/secret/bucket details. I think from then on it should be fairly straightforward. I've been running it for a year now with no issues and a lot of downloads, so it should hopefully be fairly stable when set up right.

Thanks,

Matthew

17 Apr 2012, 3:32 AM
#7
bowerstech avatar

bowerstech

New Zenner

Join Date:
Mar 2010
Posts:
83
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Hi Matthew,

Any idea about compatibility with version 1.5.0?

Thanks,
Bryan

31 Jul 2012, 1:51 PM
#8
diego_s_v avatar

diego_s_v

New Zenner

Join Date:
Jun 2011
Location:
Cariacica, Brazil
Posts:
12
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Bryan, it shouldn't be hard to merge the changes using a compare tool like Winmerge. You can also hire someone to do it for you.

6 Mar 2013, 6:31 PM
#9
ricktoxik avatar

ricktoxik

New Zenner

Join Date:
Mar 2013
Posts:
1
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Bowerstech, have you succeeded in updating your scripts?...

28 Feb 2017, 2:36 PM
#11
akasashasha avatar

akasashasha

Zen Follower

Join Date:
Mar 2009
Location:
France
Posts:
158
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Hi guys

one question about this addon: I host my file on S3 server, when clients purchase a download, everything works fine, but in Home / My account / History / Order #... the download product filename appears as this:

script:amazons3.php:CDS791.zip:132Mb

... which might not mean anything for them, and is not user-friendly at all.
Any clue how to change that so that only the filename appear (in this case CDS791.zip) ?

  • see attachement for more clarity! -

thanks a lot

Attachment 16955

28 Feb 2017, 6:23 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Remote downloads - for Amazon S3 or other

Akasashasha:

Hi guys

one question about this addon: I host my file on S3 server, when clients purchase a download, everything works fine, but in Home / My account / History / Order #... the download product filename appears as this:

script:amazons3.php:CDS791.zip:132Mb |

... which might not mean anything for them, and is not user-friendly at all.
Any clue how to change that so that only the filename appear (in this case CDS791.zip) ?

  • see attachement for more clarity! -

thanks a lot
What version of Zen Cart are you using?

I suspect your template for account history is not loading in the customized tpl_modules_downloads.php file, but is instead displaying its own download details.
I know in more recent versions of Zen Cart the account-history template loads the tpl_modules_downloads template, instead of duplicating the same thing in 2 files.

1 Mar 2017, 9:01 AM
#13
akasashasha avatar

akasashasha

Zen Follower

Join Date:
Mar 2009
Location:
France
Posts:
158
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

DrByte:

What version of Zen Cart are you using?

I suspect your template for account history is not loading in the customized tpl_modules_downloads.php file, but is instead displaying its own download details.
I know in more recent versions of Zen Cart the account-history template loads the tpl_modules_downloads template, instead of duplicating the same thing in 2 files.

Hi

thanks for this details and sorry, forgot to detail I got version 1.5.4 of zencart ...
so I checked the tpl_account_history_info_default.php and it is indeed loading the tpl_modules_downloads.php file on line 84 as follow:

/** * Used to display any downloads associated with the cutomers account */  if (DOWNLOAD_ENABLED == 'true') require($template->get_template_dir('tpl_modules_downloads.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_downloads.php');?>

... so my guess is now that in one of those files the infos selected to display the filename on account history pages are the filename set in the download attribute (which is the amazon script as in picture above).

I would like to change that so the product Model is displayed instead of the amazon script on account history pages.

Some help would be appreciated as I still did not found where to change that.

thanks

1 Mar 2017, 9:11 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Remote downloads - for Amazon S3 or other

The tpl_modules_downloads.php file for this plugin contains code to specifically check for the "script:" stuff, and if it exists then it does a special display, instead of the normal default operation. Is yours missing that section?

    if (substr($zv_filename, 0, 7) == "script:"){        list(, $zv_scriptname, $zv_filename, $zv_size) =  explode(':', $downloads->fields['orders_products_filename']);
        $is_downloadable = ( (file_exists(DIR_FS_SCRIPT . $zv_scriptname) && (($downloads->fields['download_count'] > 0 && $download_timestamp > time()) || $downloads->fields['download_maxdays'] == 0)) ) ? true : false;
        $zv_filesize = $zv_size; // "unknown";
        $zv_filesize_units = "";
    } else {
      $is_downloadable = ( (file_exists(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']) && (($downloads->fields['download_count'] > 0 && $download_timestamp > time()) || $downloads->fields['download_maxdays'] == 0)) ) ? true : false;
      $zv_filesize = filesize (DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']);
      if ($zv_filesize >= 1024) {
        $zv_filesize = number_format($zv_filesize/1024/1024,2);
        $zv_filesize_units = TEXT_FILESIZE_MEGS;
      } else {
        $zv_filesize = number_format($zv_filesize);
        $zv_filesize_units = TEXT_FILESIZE_BYTES;
      }
    }
2 Mar 2017, 9:53 AM
#15
akasashasha avatar

akasashasha

Zen Follower

Join Date:
Mar 2009
Location:
France
Posts:
158
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

Here is what I have :

if (substr($zv_filename, 0, 7) == "script:"){
        list(, $zv_scriptname, $zv_filename, $zv_size) =  explode(':', $downloads->fields['orders_products_filename']);
        $is_downloadable = ( (file_exists(DIR_FS_SCRIPT . $zv_scriptname) && (($downloads->fields['download_count'] > 0 && $download_timestamp > time()) || $downloads->fields['download_maxdays'] == 0)) ) ? true : false;
        $zv_filesize = $zv_size; // "unknown";
        $zv_filesize_units = "";
    } else {
 $is_downloadable = ( (file_exists(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']) && (($downloads->fields['download_count'] > 0 && $download_timestamp > time()) || $downloads->fields['download_maxdays'] == 0)) ) ? true : false;
      $zv_filesize = filesize (DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']);
      if ($zv_filesize >= 1024) {
        $zv_filesize = number_format($zv_filesize/1024/1024,2);
        $zv_filesize_units = TEXT_FILESIZE_MEGS;
      } else {
        $zv_filesize = number_format($zv_filesize);
        $zv_filesize_units = TEXT_FILESIZE_BYTES;
      }
    }
?>

... this section is there too, seems exactly the same as what you send ... or maybe I need new glasses ?

2 Mar 2017, 4:20 PM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Remote downloads - for Amazon S3 or other

I missed quoting a line, line 40, above the section I quoted ... should also include:```
$zv_filename = $downloads->fields['orders_products_filename'];


I'm guessing it does, else it wouldn't display correctly on checkout_success.


I'm puzzled. It makes me wonder what other plugins you've got installed that might be interfering.
2 Mar 2017, 4:30 PM
#17
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Remote downloads - for Amazon S3 or other

Could there have been a space or other "character" at the beginning of the line ($zv_filename) such that the "script:" doesn't fall in the span of the 0-7 characters? (there's no trim or other preg_ on the $zv_filename, so seems could be "anything")..

2 Mar 2017, 6:30 PM
#18
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Remote downloads - for Amazon S3 or other

Perhaps, but the complaint as I understand it is it's displaying properly on checkout_success, but not on account_history_info ... despite both sharing the same module code.

3 Mar 2017, 8:30 AM
#19
akasashasha avatar

akasashasha

Zen Follower

Join Date:
Mar 2009
Location:
France
Posts:
158
Plugin Contributions:
0

Re: Remote downloads - for Amazon S3 or other

DrByte:

Perhaps, but the complaint as I understand it is it's displaying properly on checkout_success, but not on account_history_info ... despite both sharing the same module code.

yep +1 for Dr Byte ... everything looks perfect on checkout page, but on account history page the filename that appears is this aws script applied to a download attribute instead of item model or item name ...

3 Mar 2017, 5:48 PM
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Remote downloads - for Amazon S3 or other

Hmmm .... I may not have time to investigate this until after the weekend.

I completely rewrote it and expanded its capabilities, and built it in to the v1.6.0 code. There are a lot of moving parts to it though, so may not be back-port-able. But I may have to consult what I did there to see if there's some strange missing variable here in this version.