[ic] Affiliate Program

interchange-users@interchange.redhat.com interchange-users@interchange.redhat.com
Sat Sep 22 13:06:00 2001


Quoting Sheamus Nulty (snulty@celticlinks.com):
> Hi Folks,
> 
> I'm looking for some advice with regard to setting up an affiliate program
> with interchange. Basically, the method I'm looking to implement is that a
> cookie is stored to a user's pc when he comes from an affiliate site. This
> cookie would be active for 30 Days so that the affiliate would earn
> commision on purchases made by this user during this period.
> 
> Now, I've looked at the Server.pm file and have found a way to set a
> one-time cookie that would last 30 Days by modifying the create_cookie
> routine.

I don't think that is a very good idea....but it is on your head.

Probably easier would be to use the [set-cookie] tag. You can set the
expiration explicitly with a UNIX time value or pre-formatted cookie
time string, but it seems to me that adding a certain amount of time to
the current time is a good way to set the expire, so I am making that
routine be:

sub set_cookie {
    my ($name, $value, $expire, $domain, $path) = @_;

    # Set expire to now + some time if expire string is something like
    # "30 days" or "7 weeks" or even "60 minutes"
    if($expire =~ /^\s*\d+[\s\0]*[smdhw]\S*\s*$/) {
        my $add = Vend::Config::time_to_seconds($expire);
        $expire = time() + $add if $add;
    }

    if (! $::Instance->{Cookies}) {
        $::Instance->{Cookies} = []
    }
    else {
        @{$::Instance->{Cookies}} =
            grep $_->[0] ne $name, @{$::Instance->{Cookies}};
    }
    push @{$::Instance->{Cookies}}, [$name, $value, $expire, $domain, $path];
    return;
}

in the next version. Thanks for the idea.

That will allow:

	[set-cookie name=foo value=bar expire="30 days"]

I think that would be a better way than messing with Server.pm. 

> The method I thought to use was that when a user connects to our
> site after previously coming from a affiliate, interchange would read the
> cookie and set Session->source{'mv_pc'} to the affiliate id.
> 
> This is the part I'm unsure as to how/where I should put the code to set the
> mv_pc variable.

Probably in catalog.cfg with Autoload, but this can go on any page
as well.

Autoload  <<EOF
[calc]
	return if $Session->{source};
	my $cookie = $Tag->read_cookie('cookie_name')
		or return;
	$Session->{source} = $cookie;
	return;
[/calc]
EOF

-- 
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH  45013
phone +1.513.523.7621      <mheins@redhat.com>

Few blame themselves until they have exhausted all other possibilities.
 -- anonymous