[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] softgoods -- Thanks Mike H.
Quoting Mike Heins
> If you expect to sell lots of softgoods, the best thing to do is make
> your enabling procedure provide a symlinked directory for a separate
> HTTP download.
>
> It can be as simple as:
>
> UserTag enable-download Order resource
> UserTag enable-download addAttr
> UserTag enable-download Routine <<EOR
> sub {
> my ($resource, $opt) = @_;
>
> my $docroot = $opt->{document_root} || $::Variable->{DOCROOT};
> my $dl_dir = $opt->{base_dir} || 'tmp_download';
> my $server = $opt->{server} || $::Variable->{SERVER_NAME};
>
> ## Routine comes from Vend::Util
> ## We will use session ID, but this would make totally random
> #my $random = random_string();
>
> my $random = $Vend::Session->{id};
>
> require File::Path;
>
> my $dir = "$docroot/$dl_dir/$random";
>
> if(-d $dir) {
> # Must have been made previously
> }
> elsif ( File::Path::mkpath($dir) ) {
> ## Need to ensure readable for HTTP download
> chmod 0755, $dir;
> }
> else {
> logError("Unable to make user download directory %s", $dir);
> return undef;
> }
>
> # Routine comes from Vend::Util
> unless ( file_name_is_absolute($resource) ) {
> $resource = "$Vend::Cfg->{VendRoot}/$resource";
> }
>
> # Get the base file name
> my $filebase = $resource;
> $filebase =~ s,.*/,,;
>
> ## Now do the symlink
> symlink $resource, "$dir/$filebase"
> or do {
> logError("Unable to symlink %s to %s",
> $resource, $dir);
> return undef;
> };
>
> ## Return the URL of the now-symlinked resource
> return "http://$server/$dl_dir/$random/$filebase";
> }
> EOR
>
Thanks for this great code Mike. I have decided to try and implement this
for the site.
I put this usertag in catalog.cfg. I am not that good with perl, but I think
I understand what is going on here. However
-----------------------
{SERVER_NAME} -> {www.imagemogul.com}
{DOCROOT} -> {downloads}-- I take it I should make a folder called like
"downloads" that is in my www directory
{tmp_download} -- Is this a folder called tmp_download, that will be created
on the fly, inside of {downloads}
-----------------------
Then in mail_reciept I have:
[row 82]
[column width=80 wrap=1]
Download here: [enable-download resource="/path/to/downloads/[item-field
download]"]
[/column]
[/row]
To what extent should the path/to/downloads be filled in? I have tried it
already but [enable-download resource="/path/to/downloads/[item-field
download]"] doesn't become a link, it just prints to screen.
I am trying this in catalog.cfg, because I am currently in a shared
enviroment, and don't have access to VENDROOT/usertag/. However I am in the
process of having a dedicated server setup for me, so if this won't work, I
will try it there when it is done.
Thanks again guys
Paul Jordan
- References:
- [ic] softgoods
- From: interchange-users@interchange.redhat.com (Mike Heins)