Integration with Virtue Mart is made by placing sale tracking script into the confirmation page.

1.

Edit template

Find and open file **checkout.thankyou.php

** It should be in ****administrator/components/com_virtuemart/html/

2.

Integration

Replace last ?> with following code


 $q = "SELECT * FROM #__{vm}_user_info WHERE user_id='$user_id'";
 $db->query( $q );
 $pap_user_email = $db->f('user_email');

 $q = "SELECT * FROM #__{vm}_orders WHERE order_id='$order_id'";
 $db->query( $q );
 $pap_order_subtotal = $db->f('order_subtotal' );
 $pap_coupon_code = $db->f("coupon_code");
 $pap_coupon_discount = $db->f("coupon_discount");
 if (!is_null($pap_coupon_discount) && $pap_coupon_discount != '') {
   $pap_order_total =  $pap_order_subtotal - $pap_coupon_discount;
 } else {
   $pap_order_total =  $pap_order_subtotal;
 }
 
 $q = "SELECT * FROM #__{vm}_order_item WHERE order_id='$order_id'";
 $db->query( $q );
 $pap_product_id = $db->f('product_id');
 ?>

<script type="text/javascript">var sale = PostAffTracker.createSale();
sale.setTotalCost('<?php echo $pap_order_total ?>');
sale.setOrderID('<?php echo $order_id ?>');
sale.setProductID('<?php echo $pap_product_id ?>');
sale.setData1('<?php echo $pap_user_email ?>');
sale.setCoupon('<?php echo $pap_coupon_code ?>');
PostAffTracker.register();
</script>

This code will track subtotal of the price (with coupon discount). If you want to track something else, you can use one of this variables:
order_total, order_subtotal, order_tax, order_shipping, order_shipping_tax, coupon_discount, order_discount, order_status, customer_note

Use it in the way as it is showed in the code above in the third line.

3.

Separated products

There is also possibility to generate unique transaction in PAP for every product type. With this you will have ability to edit separate product types within one order. It is useful if any refund occur. Then you will decline just one transaction (commission) assigned to product type that was refunded.
In this case please use this integration code instead of code above:

 $q = "SELECT * FROM #__{vm}_user_info WHERE user_id='$user_id'";
 $db->query( $q );
 $pap_user_email = $db->f('user_email');

 $q = "SELECT * FROM `#__{vm}_orders` WHERE `order_id`='$order_id'";
 $db->query( $q );
 $pap_coupon_code = $db->f('coupon_code');
 $pap_coupon_discount = $db->f('coupon_discount');
 $pap_order_subtotal = $db->f('order_subtotal');

 $q = "SELECT * FROM #__{vm}_order_item WHERE order_id='$order_id'";
 $number_of_items = @ mysql_fetch_array ($q);
 $db->query( $q );
 $i='0';
 while ($db->next_record()) {
  $pap_product_id[$i] = $db->f('product_id');
  $pap_item_price[$i] = $db->f('product_final_price');
  $pap_item_quantity[$i] = $db->f('product_quantity');
  $i  ;
 }
?>
 
 <script type="text/javascript">
<?php
 for ($j=0; $j<=$i; $j  ){
  $pap_final_price[$j] = ($pap_order_subtotal - $pap_coupon_discount) * $pap_item_price[$j] * $pap_item_quantity[$j] / $pap_order_subtotal;
  echo "var sale".$j." = PostAffTracker.createSale();n".
       "sale".$j.".setTotalCost('". $pap_final_price[$j]."');n".
       "sale".$j.".setOrderID('".$order_id."');n".
       "sale".$j.".setData1('".$pap_user_email."');n".
       "sale".$j.".setCoupon('".$pap_coupon_code."');n".
       "sale".$j.".setProductID('".$pap_product_id[$j]."');nn";
 }
 ?>
PostAffTracker.register();
</script>

If you want to see name of item instead of number of item use variable 'order_item_name' instead of 'product_id' in this line: $pap_product_id[$i] = $db->f('product_id');

4.

Finished

It is now integrated. Every time customer enters the order confirmationpage the tracking code is called and it will register a sale forreferring affiliate.

5.

Version 1.4

It seems like the version 1.4 needs edit of other file - checkout.result.php

It is a suggestion from one of our customers, we didn't test it.

6.

Virtue Mart with PayPal

In case you are using VirtueMart with PayPal in your Joomla, you have to do some special steps to make integration working. First, in administrator/components/com_virtuemart/notify.php (at your server) add lines below line with code: if ($_POST) {

/* PAP integration */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://URL_TO_PostAffiliatePro/plugins/PayPal/paypal.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_exec($ch);
/* end of PAP integration */

Now save the file and login to your Joomla.

7.

VirtueMart with PayPal

Navigate to Components> VirtueMart> Store> List Payment Methods> PayPal> Configuration> Payment Extra Info and add on of these lines:

"custom" => $_COOKIE['PAPVisitorId'], // for version of PAP 4.4.x.x and higher

or (depending on your PAP version)

"custom" => $_COOKIE['PAPCookie_Sale'], // for version of PAP 4.3.x.x and lower

Insert it below line with "notify_url"=>...