This is a guide to manually install Kelkoo Sales Tracking if you use Prestashop 1.6 or older.
You need to edit part of your code to succeed with this implementation.
Before setting up your Kelkoo Sales Tracking Tag
Get your merchantId and associated Country Code
See How To get your merchantId and associated Country Code
Clean any old version of Kelkoo Sales Tracking
-
In your code, remove any Kelkoo Sales tracking tag (search for leadtag.js and _kkstrack)
-
On your website backend, uninstall any Kelkoo Sales Tracking plugin you might have installed
Backup your files
Before doing any changes, please remember to back up the files you’re going to modify.
Check Recompile option
-
Go to Advanced settings -> Performance
-
Make sure option “Recompile files of template if updated” is checked.
Install the leadtag
-
Open the file themes/custom/header.tpl (where custom is the name of your template, the default being “prestashop”)
-
Add at the bottom of the file
<script async="true" type="text/javascript" src="https://s.kk-resources.com/leadtag.js" ></script>
-
Clear the cache.
Install the conversion tag
-
Open the file /controllers/front/OrderConfirmationController.php
-
Search the following line
public function initContent()
{
-
Add this code
/* Kelkoo Sales Tracking */
$order = new Order($this->id_order);
$products = $order->getProducts();
$productsKelkoo=array();
foreach ($products as $product) {
$productKelkoo=array('productname'=>$product['product_name'],
'productid'=>$product['product_reference'],
'quantity'=>$product['product_quantity'],
'price'=>$product['unit_price_tax_incl']);
array_push($productsKelkoo,$productKelkoo);
}
$this->context->smarty->assign(array(
'is_guest' => $this->context->customer->is_guest,
'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn(),
'products_json' => json_encode($productsKelkoo),
'sales' => $order->getOrdersTotalPaid(),
'orderid' => $this->id_order
));
/* end Kelkoo Sales Tracking*/
-
Go to the directory themes/custom (where custom is the name of your template, the default being “prestashop”) and open the file order-confirmation.tpl
-
Add at the bottom of the file
<script type="text/javascript">
_kkstrack = {
{literal}merchantInfo: [{ country:"COUNTRY", merchantId:"MERCHANTID_VALUE" }],{/literal}
orderValue: '{$sales}',
orderId: '{$orderid}',
basket: {$products_json}
};
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://s.kk-resources.com/ks.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
})();
</script>
Customize Conversion tag code
You need to edit some elements of the Conversion Tag
Those values can be hardcoded as they are the same for all the sales registered.
-
MERCHANTID_VALUE: This is the unique ID representing your shop within the Kelkoo Group system.
-
Check How To get your merchantId and associated Country Code.
-
If you have multiple MerchantId please check If you have multiple merchantIds and countries
-
-
COUNTRY_CODE is the 2-letter country code (lower case) for the country on which your products are listed on Kelkoo Group. Check Full list of Kelkoo Group country codes
If you have multiple merchantIds and countries
If you have several Kelkoo Group campaigns running for the same website (multiple MerchantId), you can setup all campaigns within the same tag.
You just need to have the following structure for the merchantInfo variable:
merchantInfo : [
{
country:'fr',
merchantId:'12941513'
},
{
country:'uk',
merchantId:'56789'
}
]
If you use PayPal module for payments
If you enabled PayPal payment then you have to change two additional files:
-
Open /modules/paypal/controllers/front/submit.php
-
Search for the following line inside the class PayPalSubmitModuleFrontController (you should find it at line 46)
$order = new Order($this->id_order);
-
add below
/* Kelkoo Sales Tracking */
$products = $order->getProducts();
$productsKelkoo=array();
foreach ($products as $product) {
$productKelkoo=array('productname'=>$product['product_name'],
'productid'=>$product['product_reference'],
'quantity'=>$product['product_quantity'],
'price'=>$product['unit_price_tax_incl']);
array_push($productsKelkoo,$productKelkoo);
}
$this->context->smarty->assign(array(
'is_guest' => $this->context->customer->is_guest,
'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn(),
'products_json' => json_encode($productsKelkoo),
'sales' => $order->getOrdersTotalPaid(),
'orderid' => $this->id_order
));
/* end Kelkoo Sales Tracking*/
-
Open /modules/paypal/views/templates/front/order-confirmation.tpl
-
Add at the bottom of the file
<script type="text/javascript">
_kkstrack = {
{literal}merchantInfo: [{ country:"COUNTRY", merchantId:"COM_ID" }],{/literal}
orderValue: '{$sales}',
orderId: '{$orderid}',
basket: {$products_json}
};
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://s.kk-resources.com/ks.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
})();
</script>
Clear Prestashop Cache
Admin > Advanced Paramaters > Performance > Clear Cache
Test your integration
Please check Test Integration
If you face issues
Please check Common Issues with Prestashop Integration before contacting the support.