Interspire Shopping Cart integration
Een functierijke winkelwagensoftware die alles bevat wat u nodig hebt om uw online winkel te starten, uit te voeren en te promoten. Deze integratiemethode van By Dustin Holdiman helpt je om PAP te integreren met Interspire Shopping Cart 5.0+.
Waar is dit script voor?
Deze opstelling is gemaakt om elk product en de hoeveelheid besteld product in de Interspire-winkelwagen bij te houden. Wat dit script doet, is om elk besteld product als een afzonderlijke verkoop naar PAP te posten. Op deze manier, als een gebruiker 3 verschillende producten koopt en 2 van elk van die producten, worden er 6 verkopen geregistreerd bij PAP en weet u de juiste commissie om de aangeslotene te betalen.
Hoe PAP in te stellen om met dit script te werken
Hoe de Interspire-winkelwagen in te stellen
// Include the conversion tracking code for affiliates
foreach ($this->pendingData['orders'] as $order) {
if (strlen(GetConfig('AffiliateConversionTrackingCode')) > 0) {
......
......
}
Vervangen van de code (geldt voor versie 5.x van Interspire Shopping Cart)
Kopieer de hele lus en vervang deze door de volgende code:
//////////////////////////////////////////////////////////////////////////////////////////////////
foreach ($this->pendingData['orders'] as $order) {
if (strlen(GetConfig('AffiliateConversionTrackingCode')) > 0) {
$converted_code = GetConfig('AffiliateConversionTrackingCode');
$converted_code = str_ireplace('%%ORDER_AMOUNT%%', $order['ordsubtotal'], $converted_code);
$converted_code = str_ireplace('%%ORDER_ID%%', $order['orderid'], $converted_code);
//retreive customer id for the particular order in order to take use of Lifetime Commissions
$query_custid = "SELECT ordcustid FROM isc_orders WHERE orderid='".$order['orderid']."'";
$result_custid = mysql_query($query_custid);
$custid = mysql_fetch_row($result_custid);
$customerid = $custid[0];
$query_proid = "SELECT * FROM isc_order_products WHERE orderorderid='".$order['orderid']."'";
$result_proid = mysql_query($query_proid);
$prod_data = '';
// Setup string to look like PRODUCTID:QUANTITY:PRICE,
while ($row_proid = mysql_fetch_array($result_proid)) {
$prodarr[] = $row_proid['ordprodid'].':'.$row_proid['ordprodqty'].':'.$row_proid['ordprodcost'];
}
$java_arr[] = "<script type=\"text/javascript\">
PostAffTracker.setAccountId('Account_ID');"; // Start javascript array
$prod_count = '1'; // Product Counter
// Separate string by ,
foreach ($prodarr as $value) {
// Split apart string by : (PRODUCTID:QUANTITY:PRICE)
$prod_info = explode(":", $value);
// Not needed but here for referance
//$converted_code = str_ireplace('%%PRODUCT_ID'.$prod_count.'%%',$prod_info[0], $converted_code);
//$converted_code = str_ireplace('%%QUANTITY_ID'.$prod_count.'%%',$prod_info[1], $converted_code);
// Create sale code for each product x the quantity ordered
$quantity = $prod_info[1];
while ($quantity >= 1){
$java_string = "
var sale".$prod_count." = PostAffTracker.createSale();
sale".$prod_count.".setTotalCost('".$prod_info[2]."');
sale".$prod_count.".setOrderID('".$order['orderid']."(".$prod_count.")');
sale".$prod_count.".setProductID('".$prod_info[0]."');
sale".$prod_count.".setData1('".$customerid."');";
$java_arr[] = $java_string;
$img_arr[] = '<img src="https://URL_TO_PostAffiliatePro/scripts/sale.php?TotalCost='.$prod_info[2].'&OrderID='.$order['orderid'].'_'.$prod_count.'&ProductID='.$prod_info[0].'" width="1" height="1">';
$prod_count++; // Increase Product Counter by 1
$quantity = $quantity-1;
}
}
// Image Loop - Returns $img as all img src created in foreach loop
$img = implode("", $img_arr);
// Finish off javascript code
$java_arr[] = "
PostAffTracker.register();
</script>";
// Build string from array created in for each loop
$java = implode("", $java_arr);
$converted_code = str_ireplace('%%JAVA%%', $java, $converted_code); // Simply Insert %%JAVA%% into affiliate tracking section of interspire
$converted_code = str_ireplace('%%IMG_CODE%%', $img, $converted_code); // Simply Insert %%IMG_CODE%% into affiliate tracking section of interspire
$GLOBALS['ConversionCode'] .= $converted_code;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// End Edit
}
Sla het bestand nu eenvoudig op.
De code vervangen (geldt voor versie 6.x van Interspire Shopping Cart)
Kopieer de hele lus en vervang deze door de volgende code:
//////////////////////////////////////////////////////////////////////////////////////////////////
foreach ($this->pendingData['orders'] as $order) {
if (strlen(GetConfig('AffiliateConversionTrackingCode')) > 0) {
$converted_code = GetConfig('AffiliateConversionTrackingCode');
$converted_code = str_ireplace('%%ORDER_AMOUNT%%', $order['ordsubtotal'], $converted_code);
$converted_code = str_ireplace('%%ORDER_ID%%', $order['orderid'], $converted_code);
//retreive customer id for the particular order in order to take use of Lifetime Commissions
$query_custid = "SELECT ordcustid FROM ".$GLOBALS['ISC_CFG']["tablePrefix"]."orders WHERE orderid='".$order['orderid']."'";
$result_custid = mysql_query($query_custid);
$custid = mysql_fetch_row($result_custid);
$customerid = $custid[0];
//check if there was a coupon used and get it's code
$query_coupon = 'SELECT ordcouponcode FROM '.$GLOBALS['ISC_CFG']['tablePrefix']."order_coupons WHERE ordcouporderid='".$order['orderid']."'";
$result_coupon = mysql_query($query_coupon);
try {
$couponrow = mysql_fetch_row($result_coupon);
$coupon = $couponrow[0];
}
catch (Exception $e) {
// no coupon found
$coupon = '';
}
$query_proid = "SELECT * FROM ".$GLOBALS['ISC_CFG']["tablePrefix"]."order_products WHERE orderorderid='".$order['orderid']."'";
$result_proid = mysql_query($query_proid);
$prod_data = '';
// Setup string to look like PRODUCTID:QUANTITY:PRICE,
while ($row_proid = mysql_fetch_array($result_proid)) {
$prodarr[] = $row_proid['ordprodid'].':'.$row_proid['ordprodqty'].':'.$row_proid['base_price'].':'.$this->sumDiscountAndCoupon($row_proid['applied_discounts']);
}
$java_arr[] = "<script type=\"text/javascript\">
PostAffTracker.setAccountId('Account_ID');"; // Start javascript array
$prod_count = '1'; // Product Counter
// Separate string by ,
foreach ($prodarr as $value) {
// Split apart string by : (PRODUCTID:QUANTITY:PRICE)
$prod_info = explode(":", $value);
// Not needed but here for referance
//$converted_code = str_ireplace('%%PRODUCT_ID'.$prod_count.'%%',$prod_info[0], $converted_code);
//$converted_code = str_ireplace('%%QUANTITY_ID'.$prod_count.'%%',$prod_info[1], $converted_code);
// Create sale code for each product x the quantity ordered
$totalCost = $prod_info[2]-($prod_info[3]/$prod_info[1]);
$quantity = $prod_info[1];
while ($quantity >= 1){
$java_string = "
var sale".$prod_count." = PostAffTracker.createSale();
sale".$prod_count.".setTotalCost('".$totalCost."');
sale".$prod_count.".setOrderID('".$order['orderid']."(".$prod_count.")');
sale".$prod_count.".setProductID('".$prod_info[0]."');
sale".$prod_count.".setData1('".$customerid."');";
if (!empty($coupon)) $java_string .= "sale".$prod_count.".setCoupon('$coupon');";
$java_arr[] = $java_string;
$img_arr[] = '<img src="https://URL_TO_PostAffiliatePro/scripts/sale.php?TotalCost='.$totalCost.'&OrderID='.$order['orderid']."_".$prod_count.'&ProductID='.$prod_info[0].'&Coupon='.$coupon.'" width="1" height="1" />';
$prod_count++; // Increase Product Counter by 1
$quantity = $quantity-1;
}
}
// Image Loop - Returns $img as all img src created in foreach loop
$img = implode("", $img_arr);
// Finish off javascript code
$java_arr[] = "
PostAffTracker.register();
</script>";
// Build string from array created in for each loop
$java = implode("", $java_arr);
$converted_code = str_ireplace('%%JAVA%%', $java, $converted_code); // Simply Insert %%JAVA%% into affiliate tracking section of interspire
$converted_code = str_ireplace('%%IMG_CODE%%', $img, $converted_code); // Simply Insert %%IMG_CODE%% into affiliate tracking section of interspire
$GLOBALS['ConversionCode'] .= $converted_code;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// End Edit
}
Sla het bestand nu eenvoudig op.
Functies toevoegen voor rekenkorting (geldt voor versie 6.x van Interspire Shopping Cart)
//////////////////////////////////////////////////PAP integration functions
//find all occurences of a needle inside a haystack
private function strposall($haystack, $needle){
$s=0;
$i=0;
while (is_integer($i)){
$i = strpos($haystack,$needle,$s);
if (is_integer($i)) {
$aStrPos[] = $i;
$s = $i+strlen($needle);
}
}
if (isset($aStrPos)) {
return $aStrPos;
}
else {
return false;
}
}
private function getDiscountFromPosition($discountsString, $position) {
$substring = substr($discountsString, $position+2);
return substr($discountsString, $position+2, strpos($substring, ';'));
}
private function sumDiscountAndCoupon($discountsString) {
if (is_null($discountsString) || $discountsString == '' || !strstr($discountsString, 'd:')) {
return 0;
}
$sum = 0;
foreach ($this->strposall($discountsString, 'd:') as $position) {
$sum += $this->getDiscountFromPosition($discountsString, $position);
}
return $sum;
}
/////////////////////////////////////////////////end PAP integration functions
De Interspire-instellingen instellen
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
%%JAVA%%
Het wordt niet aanbevolen om Interpsire-integratie samen met PayPal-integratie (of integratie van een andere betalingsverwerker ondersteund door Interspire) plug-in te gebruiken. Dit kan leiden tot dubbel bijgehouden transacties. U moet een bescherming tegen verkoopfraude instellen om ze te vermijden.
Interspire handelt alle transacties zelf af (verwerkt alle transacties ongeacht de betaalmethode) en daarom dient u alleen deze Interspire Integration te gebruiken. Als deze integratie niet geschikt voor u is, probeer dan een alternatieve.