We are in the process of creating a specialty cart where our when a client makes a purchase it logs the Affiliate id in the database at time of purchase. I have created the following code to get the affiliate id/name using the Post Affiliate Pro API.
include ("affiliate/api/PapApi.class.php");
$session = new Gpf_Api_Session("https://www.elitespecialtymeats.com/affiliate/scripts/server.php");
if(!$session->login("user", "password")){ die("Cannot login. Message: ".$session->getMessage()); }
$clickTracker = new Pap_Api_ClickTracker($session);
try {
$clickTracker->track();
$clickTracker->saveCookies();
if ($clickTracker->getAffiliate() != null){ $affid=$clickTracker->getAffiliate()->getValue('username'); }
else{ $affid=''; }
}catch (Exception $e){
$affid='';
}
I am trying to figure out the best way of adding that id into the purchase. I think it may be best to add it in tpl_checkout_success_default.php where they log the purchase into PAP. My issue is that I dont know enough about the system to implement the code.
My best guess is
$db->Execute("UPDATE ".TABLE_ORDERS_TOTAL." SET affid='$affid' where orders_id = '".(int)$orders->fields['orders_id']."' AND class in ('ot_coupon', 'ot_gv', 'ot_subtotal', 'ot_group_pricing', 'ot_quantity_discount')");
Will this work or will i mess something up?
First of all, using the API you are loading affiliate username ( …getValue(‘username’) ), not affiliate ID as you stated in the first paragraph. You should use getValue(‘userid’); (for affiliate ID) or getValue(‘refid’); (for referral ID).
The database command you are trying to use will only work in case the the table TABLE_ORDERS_TOTAL has a column called ‘affid’. You can add it manually to the table…
I am wondering why are you doing something like this… It seems like you want to use the ID for some special purpose later. Do you want to give a commission to the original referring person even the customer removed all the cookies or clicked another affiliate’s banner meanwhile? If so, you should use Lifetime commissions instead:
http://support.qualityunit.com/541587-Lifetime-commissions
In case you need any other help, feel free to contact our online support.