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:
locate the </header> tag and add the next code just before it:
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.
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.
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:
- On your Affiliatly account, go to the integrations tab
- On integration method, click on "PHP"
- Click on the link to download the file "php_v3.zip" to download it to your computer
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:
- Enter to your hosting service account
- Open the file manager for your store
- Upload the "api_affiliatly.php" file to the "public_html" folder
This is how the result should look like:
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';
$result = affiliatly_mark_purchase('AF-10XXX', $this->id_order, $total_to_pay, $security_hash);
The result should look like this:
In the integration code:
- Replace the XXXX in $security_hash with your own security hash. You can find it on your Affiliatly admin panel under Account->Security Hash
- 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.
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.