This integration method by By Dustin Holdiman will help you to integrate PAP with Interspire Shopping Cart 5.0+

1.

What is this script for?

This setup was created to track each product and quantity of product ordered in Interspire Shopping Cart. What this script does is to post each product ordered as a separate sale to PAP. This way, if a user purchases 3 different products and 2 of each of those products, 6 sales will be registered with PAP and you will know the correct commission to pay the affiliate.

2.

How to setup PAP to work with this script

First you need to create a campaign for EACH item that should has a different commission. So for instance, Product A gets a $10 commission, Product B is $12 and Product C is $8. I will create 3 campaigns and for assign the Product ID to each campaign that is set by Interspire. By default you can find this information in the database by looking in the table isc_products and checking the productid cell. After you have setup your campaigns that's all you need to do with PAP to continue.

3.

How to setup Interspire Shopping Cart

You need to edit the file class.order.php. This script is found in your Interspire install directory in includes/classes/class.order.php.Scroll the file down to around line 178. You are looking for the foreach loop that is commented. This is the code:

// Include the conversion tracking code for affiliates
foreach ($this->pendingData['orders'] as $order) {
  if (strlen(GetConfig('AffiliateConversionTrackingCode')) > 0) {
......
......
}

4.

Replacing the code (applies to version 5.x of Interspire Shopping Cart)

Copy the entire foreach loop and replace it with the following 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="http://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
        }

Now simply save the file.

5.

Replacing the code (applies to version 6.x of Interspire Shopping Cart)

Copy the entire foreach loop and replace it with the following 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="http://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
        }

Now simply save the file.

6.

Add functions for computing discount (applies to version 6.x of Interspire Shopping Cart)

You are editting the file class.order.php still. Add the following code right before line: private function ThanksForYourOrder()

        //////////////////////////////////////////////////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

7.

Setting up the Interspire settings

Openup your administration panel in Interspire, goto Settings / Affiliate Settingsand paste the following code into the textarea.

<script id="pap_x2s6df8d" src="http://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script> 
%%JAVA%%

Or if you do not wish to use javascript toreport to PAP, you can use the IMG SRC tag by replacing %%JAVA%% with %%IMG_CODE%%

NOTE: Using PayPal integration plugin with Interspire integration

It is not recommended to use Interpsire integration along with PayPal integration (or integration of another payment processor supported by Interspire) plugin. This can lead to double-tracked transactions. You need to set up a sale fraud protection to avoid them.
Interspire is handling all transactions (processes all transactions regardless the payment method) itself and because of that, you should use this Interspire Integration only.
If this integration is not suitable for you try an alternative one


Any questions / comments / suggestions please email Dustin dmanz013@gmail.com