Foxy Cart integration
A hosted e-commerce solution that was built specifically with web developers in mind.
Login
Log into your FoxyCart store’s AdminPage, go to Templates > Receipt. In case there is no code yet, click to the FoxyCart Standard template.
Integration – track whole cart as one transaction
Above the tag of the code of receipt template insert the following code:
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
var ototal = '{{ total_order }}';
var odiscount = '{{ total_discount }}';
var oshipping = '{{ total_shipping }}';
var otax = '{{ total_tax }}';
var ofinalprice = ototal - odiscount - oshipping - otax;
PostAffTracker.setAccountId('default1');
var sale = PostAffTracker.createSale();;
sale.setTotalCost(ofinalprice);
sale.setOrderID('{{ order_id }}');
PostAffTracker.register();
</script>
Click the update template button and save your work.
For older versions of FoxyCart skip the rows that declare (define) the ‘ototal‘, …, ‘ofinalprice‘ variables and instead of these 2 lines of code:
sale.setTotalCost(ofinalprice);
sale.setOrderID('{{ order_id }}');
use these following in the code given in the box above:
sale.setTotalCost('^subtotal^');
sale.setOrderID('^order_id^');
If you wish to track the customer’s email address into the ‘Data1’ parameter of sale tracking code in order to utilize Lifetime Commissions, then right above:
PostAffTracker.register();
add the following code:
sale.setData1('{{ customer_email }}');
In older versions use ^customer_email^ instead of {{ customer_email }} .
Coupon tracking
In case you would like to use coupon tracking, use this version of code:
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('Account_ID');
var sale = PostAffTracker.createSale();
var coupon_code = "";
if(FC.json.hasOwnProperty('coupons')) {
$.each(FC.json.coupons, function(i, coupon){
if(coupon.name.search(/CS4/i) > -1) {
coupon_code = coupon.name;
}
});
}
var ototal = '{{ total_order }}';
var odiscount = '{{ total_discount }}';
var oshipping = '{{ total_shipping }}';
var otax = '{{ total_tax }}';
var ofinalprice = ototal - odiscount - oshipping - otax;
PostAffTracker.setAccountId('default1');
var sale = PostAffTracker.createSale();;
sale.setTotalCost(ofinalprice);
sale.setOrderID('{{ order_id }}');
sale.setCoupon(coupon_code);
PostAffTracker.register();
</script>
Integration – tracking each product as a separate transaction
This option is available for FoxyCart version 2.0 and higher.
If you wish to take use of product id matching capability of Post Affiliate Pro, then you need to use a different integration code instead of the one mentioned in step no. 3.
Here is the code to be used:
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
{% set counter = 0 %}
{% for item in items %}
<script type="text/javascript">
PostAffTracker.setAccountId('deafult1');
var sale{{ counter }} = PostAffTracker.createSale();
sale{{ counter }}.setTotalCost('{{ item.price }}');
sale{{ counter }}.setProductID('{{ item.code }}');
sale{{ counter }}.setOrderID('{{ order_id }}_{{ counter }}');
sale{{ counter }}.setData1('{{ customer_email }}');
PostAffTracker.register();
</script>
{% set counter = counter + 1 %}
{% endfor %}
That’s it.
Integration – tracking each product as a separate transaction + coupon tracking
This option is available for FoxyCart version 2.0 and higher.
If you wish to utilize coupon tracking along with the per product tracking, then use the following code instead of the one in step no.5.
This option is available for FoxyCart version 2.0 and higher.
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
{% set counter = 0 %}
{% for item in items %}
<script type="text/javascript">
var coupon_code = "";
if(FC.json.hasOwnProperty('coupons')) {
$.each(FC.json.coupons, function(i, coupon){
if(coupon.name.search(/CS4/i) > -1) {
coupon_code = coupon.name;
}
});
}
PostAffTracker.setAccountId('deafult1');
var sale{{ counter }} = PostAffTracker.createSale();
sale{{ counter }}.setTotalCost('{{ item.price }}');
sale{{ counter }}.setProductID('{{ item.code }}');
sale{{ counter }}.setOrderID('{{ order_id }}_{{ counter }}');
sale{{ counter }}.setCoupon(coupon_code);
sale{{ counter }}.setData1('{{ customer_email }}');
PostAffTracker.register();
</script>
{% set counter = counter + 1 %}
{% endfor %}
If you wanted to track some more details into the Extra Data 2-5 fields of sale tracking code, check out the details available in the receipt template of foxycart:
https://wiki.foxycart.com/v/2.0/receipt
Foxycart supports twig syntax:
http://twig.sensiolabs.org/doc/templates.html