PDA

View Full Version : Javascript question


badkarma
16th October 2004, 04:12 AM
Normally with this program you have to place the javascript General Sale Registration Code on a page where the sale has been successfull.

My problem is, that I also work with an affiliate system from a third party and they of course do not want to integrate this code for me. :( . I figured our a solution to this: My buy-now button takes my clients to my affiliate third party booking engine. I thought that, when pressed on the buy now button, the chance of a sale is the highest. Here I then come to my question: can someone give me an example of the General Sale Registration Code being activated when pressed on a button?

Greetings,

JOhn

mark
18th October 2004, 12:21 PM
Hello,

I tried to make it work somehow and I got this solution:
when your button is clicked, its onclick event is called and it will call function that opens new window in the background. This window will register the sale and then it will automatically close.
On the main page the form is submitted normally and user will proceed do PayPal.

It will require using customized version of sale.php script, but it is quite simple.

Contact me by email on info@webradev.com and I can send you the code with more description + file that has to be changed in affiliate system.

regards,

mark

stuff
28th October 2004, 05:47 AM
Hello,

I tried to make it work somehow and I got this solution:
when your button is clicked, its onclick event is called and it will call function that opens new window in the background. This window will register the sale and then it will automatically close.
On the main page the form is submitted normally and user will proceed do PayPal.

It will require using customized version of sale.php script, but it is quite simple.

Contact me by email on info@webradev.com and I can send you the code with more description + file that has to be changed in affiliate system.

regards,

mark

I have the same problem, cant you post all info in this forum ?

Tnx

mark
29th October 2004, 07:34 PM
Hi,

I'm publishing the code of my solution to be available to everyone.

There is one disadvantage of this solutions, and it is that if user
has blocked pop-ups, it will not work, because it will not open new
window.

You should put this code to your paypal submit button:

<input name="submit" type="submit" value="Buy now" onClick="javascript:sendAff(getCookie('POSTAff2Cookie'), 'Product1',123.45);">


you also have to add the following functions between <head>..</head> tags:

<script>
function getCookie(name)
{
var nameequals = name + "=";
var beginpos = 0;
var beginpos2 = 0;
while (beginpos < document.cookie.length)
{
beginpos2 = beginpos + name.length + 1;
if (document.cookie.substring(beginpos, beginpos2) == nameequals)
{
var endpos = document.cookie.indexOf (";", beginpos2);
if (endpos == -1)
endpos = document.cookie.length;
return unescape(document.cookie.substring(beginpos2, endpos));
}
beginpos = document.cookie.indexOf(" ", beginpos) + 1;
if (beginpos == 0)
break;
}

return null;
}

function sendAff(val, ProductID, TotalCost)
{
var wnd =
window.open("http://www.yourdomain.com/affiliate/scripts/sale2.php?cid="+val+"&ProductID="+ProductID+"&TotalCost="+TotalCost,"AddAffiliate","scrollbars=1,
top=1000, left=1000, width=1, height=1, status=0")
this.focus();
}
</script>


Except the code above, you should also crea
te customized sale2.php script
in the /scripts directory.

sale2.php

<?php
// include files
require_once('global.php');

DebugMsg("Sale registration: Start registering sale, params TotalCost='".$_GET['TotalCost']."', OrderID='".$_GET['OrderID']."', ProductID='".$_GET['ProductID']."'", __FILE__, __LINE__);

$TotalCost = preg_replace('/[^0-9\.]/', '', $_GET['TotalCost']);
$OrderID = preg_replace('/[\'\"\ ]/', '', $_GET['OrderID']);
$ProductID = preg_replace('/[\'\"\ ]/', '', $_GET['ProductID']);
$cookie = $_GET['cid'];

$saleReg = new SaleRegistrator();

// register sale
if($saleReg->decodeData($cookie))
$saleReg->registerSale($TotalCost, $OrderID, $ProductID);
else
DebugMsg("Sale registration: Data not decoded, failed to save sale", __FILE__, __LINE__);

DebugMsg("Sale registration: End registering sale", __FILE__, __LINE__);
?>
<html>
<body>
<script>
this.close();
</script>
</body>
</html>


regards,

mark

stuff
30th October 2004, 12:28 AM
Mark,

Thanks for this mini tutorial with script, its helping me alot with rewarding the correct affiliate for my 3' party sales ! :D

Since its very hard to track these sales, this will help when you can see it as a pending sale from that affiliate.

Tnx