How to integrate with PrestaShop

To integrate Affiliatly with PrestaShop, you need to add two different codes: one for tracking referred visitors and for tracking purchases made by those referred visitors.


Adding the visitor tracking script


Open your header.tpl file, its located in the currently loaded theme, by default its:


/themes/NAME_OF_YOUR_THEME/templates/_partials/header.tpl


locate the </header> tag and add the next code just before it:

<script src="https://static.affiliatly.com/v3/affiliatly.js?affiliatly_code=AF-10XXXXX"></script>

Note: in the integration code, when you see β€œAF-10XXX”, you need to replace it with your own Affiliate ID as that is just an example.

Visitor tracking code inserted on head file

To test your integration, open your site with β€œ?aff=1” parameter at the end of the address. If everything was done correctly you should see a referred visit on your dashboard.

Affiliate visit successfully tracked and shown on dashboard


Adding the purchases tracking script


Being able to track purchases requires to make two procedures. Don't worry, we'll make our best to have this guide cover the details involved.

Process 1: placing the API file on your server

First, we'll need to get one file needed for this process:

  1. On your Affiliatly account, go to the integrations tab
  2. On integration method, click on "PHP"
  3. Click on the link to download the file "php_v3.zip" to download it to your computer

How to locate the PHP file inside Affiliatly

After that, please unzip the file and you'll get a file named "api_affiliatly.php" that we're going to use on the next step.


Now we need to upload that file to your server. The exact steps may differ depending on which hosting service you use but here's what you need to do:

  1. Enter to your hosting service account
  2. Open the file manager for your store
  3. Upload the "api_affiliatly.php" file to the "public_html" folder

This is how the result should look like:

API file uploaded on server

Process 2: adding the tracking code for purchases

Open the file /controllers/front/OrderConfirmationController.php and find this string:

public function displayOrderConfirmation($order)

{

Add the following code below that bracket:

//====

$order = new Order($this->id_order);

$shipping = 0;

foreach($order->getShipping() as $k=>$v)

{

   $shipping += $v['shipping_cost_tax_incl'];

}

$total_to_pay = $order->getOrdersTotalPaid() - $shipping;

$security_hash = 'XXXX';

require_once($_SERVER['DOCUMENT_ROOT'].'/api_affiliatly.php');

$result = affiliatly_mark_purchase('AF-10XXX', $this->id_order, $total_to_pay, $security_hash);

//====

The result should look like this:

Code inserted properly in the order confirmation controller file

In the integration code:

  1. Replace the XXXX in $security_hash with your own security hash. You can find it on your Affiliatly admin panel under Account->Security Hash
  2. When you see β€œAF-10XXX”, you need to replace it with your own Affiliate ID as that is just an example.

To test your integration, open your site with β€œ?aff=1” parameter at the end of the address and make a test purchase.

After you have placed your order, you should see it in appear in your Affiliatly’s dashboard in the next minutes.

tracked purchase shown on dashboard

tracked purchase shown in referred order details

You're all set!

This is the end for this PrestaShop integration guide. If you have any more questions and the answers are not available here, please contact us and we will gladly assist you.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us