Integration with ZenCart is made by placing sale tracking script into the order confirmation page.

1.

Edit template

To integrate ZenCart you should edit the order confirmation template. Open the file includes/templates/template_default/templates/tpl_checkout_success_default.php

2.

Locate integration place

Find the line with following code which should already exist in the file.
<div id="checkoutSuccessOrderNumber"><?php echo TEXT_YOUR_ORDER_NUMBER . $zv_orders_id; ?></div>

3.

Integration

Copy & Paste the following code into the file, under the line found above:

<?php
$dbreq = $db->Execute("select * from ".TABLE_ORDERS_TOTAL." where orders_id = '".(int)$orders->fields['orders_id']."' AND class in ('ot_coupon', 'ot_gv', 'ot_subtotal', 'ot_group_pricing', 'ot_quantity_discount')");
while (!$dbreq->EOF) {
  switch ($dbreq->fields['class']) {
    case 'ot_subtotal': $order_subtotal = $dbreq->fields['value']; break;
    case 'ot_coupon': $coupon_amount = $dbreq->fields['value']; $coupon_code = $dbreq->fields['title']; break;
    case 'ot_group_pricing': $group_pricing_amount = $dbreq->fields['value']; break;
    case 'ot_gv': $gv_amount = $dbreq->fields['value']; break;
    case 'ot_quantity_discount': $quantity_discount_amount = $dbreq->fields['value']; break;
  }
  $dbreq->MoveNext();
}
$totalCost = ($order_subtotal - $gv_amount - $coupon_amount - $group_pricing_amount - $quantity_discount_amount);
$totalCost = number_format($totalCost,2,'.','');
$orderId = $dbreq->fields['orders_id'];

// ------------- coupon code --------------------------------------------------
$coupon_code = substr($coupon_code,(strpos($coupon_code,":")) 2);
$coupon_code = substr($coupon_code,0,strlen($coupon_code)-2);

// -------------products---------------------------------------------------------
$productId = "";
$dbreqa = $db->Execute("select products_id from ".TABLE_ORDERS_PRODUCTS." where orders_id = '".(int)$orders->fields['orders_id']."' ");
while (!$dbreqa->EOF) {
  $productId = $dbreqa->fields['products_id'];
  $dbreqa->MoveNext();
}
// ----------end products--------------------------------------------------------

print '
<script type="text/javascript">';
print "";
print 'var sale = PostAffTracker.createSale();
sale.setTotalCost(''.$totalCost.'');
sale.setOrderID(''.$orderId.'');
sale.setProductID(''.$productId.'');
sale.setCoupon(''.$coupon_code.'');
PostAffTracker.register();
</script>';
?>

Ok, the integration is finished. Now every time a sale occurs, the shop will call our script and register the sale commission.

4.

Lifetime commissions integration

If you want to integrate the Lifetime commissions plugin, then just add the code below into the code from step 3. after this line:
$orderId = $dbreq->fields['orders_id'];

$dbreq = $db->Execute("select * from ".TABLE_ORDERS_TOTAL." where orders_id = '".(int)$orders->fields['orders_id']."' ");
while (!$dbreq->EOF) {
  $email = $dbreq->fields['customers_email_address'];
  $dbreq->MoveNext();
}

Also you need to add this code: sale.setData1(''.$email.'');
right after the sale.setOrderID(''.$orderId.'');


In case you want to know the payment method name used in the order, you can use this variable:
$orders->fields['payment_method']


5.

zenCart + PayPal - part 1

In case you use PayPal as a payment gateway in ZenCart then a different integration approach is needed.

In 'zenCart_installation_directory/includes/functions/html_output.php' find the following line:

$field = '<input type="hidden" name="' . zen_sanitize_string(zen_output_string($name)) . '"';

and replace it with this one:

if ($name == 'notify_url') {
	$field = '<input type="hidden" id="pap_ab78y5t4a" name="' . zen_output_string($name) . '"';
} else {
	$field = '<input type="hidden" name="' . zen_output_string($name) . '"';
}

6.

zenCart + PayPal - part 2

Into 'zenCart_installation_directory/includes/templates/template_default/common/tpl_footer.php' add the following code:

<!-- PAP Integration snippet -->
<script type="text/javascript">
	document.write(unescape("%3Cscript id=%27pap_x2s6df8d%27 src=%27" + (("https:" == document.location.protocol) ? "https://" : "http://") + "URL_TO_PostAffiliatePro/scripts/trackjs.js%27 type=%27text/javascript%27%3E%3C/script%3E"));
</script>
<script type="text/javascript">
PostAffTracker.setAccountId('default1');
PostAffTracker.writeCookieToCustomField('pap_ab78y5t4a', '', 'pap_custom'); 
</script>
<!-- /PAP Integration snippet -->

7.

zenCart + PayPal - part 3

Into 'zenCart_installation_directory/ipn_main_handler.php' add the following code:

/* Post Affiliate Pro integration snippet */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://URL_TO_PostAffiliatePro/plugins/PayPal/paypal.php?pap_custom=".$_GET['pap_custom']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_exec($ch);
/* /Post Affiliate Pro integration snippet */

That's it. 

Now, log in to the merchant panel of Post Affiliate Pro (Network), navigate to the "Plugins" section and activate the "PayPal IPN Handling" plugin.

<u>NOTE:</u> If you wish to enable Lifetime Commission integration when using this 'zenCart + PayPal' integration method, then in the configuratoin of  "PayPal IPN Handling" plugin turn on the 'Support lifetime commission' option.

Do not forget to integrate your site with the click tracking code to make the sale tracking working correctly.