Explanation: Implement Daisycon conversion pixel in OpenCart

Daisycon has developed an implementation script of the conversion pixel for OpenCart. 

Besides a solution for OpenCart, there are more possibilities to implement the conversion pixel in other webshops. Read here how to implement the conversion pixels for other content management systems.

To use the conversionixel for OpenCart you need to add scripts in three files.

1. In the first file you need to add the script below. This file can be found at the following location: catalog/view/theme/[theme]/template/common/success.tpl

<?php
/**
 * Daisycon Conversion Pixel for OpenCart
 *
 * Copyright (c) 2019 Daisycon (http://www.daisycon.com)
 *
 */
 
	// Add this to the file in the following path: catalog/view/theme/[theme]/template/common/success.tpl
	$iProgramId = 0; // Insert your Program ID here

	// Add the matching domain here. Need help? Ask your contact at Daisycon for more information.
	$sMatchingDomain = ''; //For example: lt45.net, ds1.nl, dt51 or any other given from the channel manager
	
	if(isset($orderDetails) && isset($orderProducts)) {
	
		$aVariables = array(
			'si' => $iProgramId,
			'ti' => $orderDetails['order_id'],
			'oa' => substr($orderProducts[0]['name'], 0, 50),
			'om' => substr($orderProducts[0]['name'], 0, 50),
			'bd' => number_format(($orderDetails['total'] - $shippingDetails['cost']), 2, '.', ''),
			'pc' => $orderDetails['shipping_postcode'],
			'rv' => number_format(($orderDetails['total'] - $shippingDetails['cost']), 2, '.', ''),
		);
		
		$sUrl = "//".$sMatchingDomain."/t/";
		$sGlue = "?";

		foreach ($aVariables as $sKey => $mValue)
		{
			$sUrl .= $sGlue.$sKey."=".urlencode($mValue);
			$sGlue = "&";
		} 
		
		echo '<img src="'.$sUrl.'" style="border: 0px; height: 1px; width: 1px;" alt="Adverteren via Daisycon" />';
		
		echo "<script type='text/javascript'>window.onload=function(){setTimeout(function(){im=document.getElementsByTagName('img');for(i=0;i<im.length;i++){o=im[i];if(/[s|c]i=/i.exec(o.src)&&(!o.offsetHeight||o.offsetHeight<1)){i=document.createElement('img');i.height='1';i.width='1';i.id='news';i.className='net';i.src='//'+Math.round(+new Date()/83000)+'.'+i.id+'tat.'+i.className+'/ab/'+o.src.substring(o.src.indexOf('?'),o.src.length);document.body.appendChild(i);}}},100);}</script>";
	}	
?>

Don't forget to replace the "0" by your campaign ID, you will find your campaign ID next to your campaign name in the tracking menu of your advertiser log-in. Please ask your channel manager if you have any trouble finding it.

2. The script below must be placed in the file catalog/controller/checkout/success.php.

/**
 * Start Daisycon Conversion Pixel for OpenCart
 */
 
$this->load->model('checkout/order');
$this->data['shippingDetails'] = $this->session->data['shipping_method']; 
$this->data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$this->data['orderProducts'] = $this->model_checkout_order->getOrderProducts($this->session->data['order_id']);

/**
* End Daisycon Conversion Pixel for OpenCart
*/   

3. The script below must be placed in the file catalog/model/checkout/order.php.

/**
 * Start Daisycon Conversion Pixel for OpenCart
 */
 
public function getOrderProducts($order_id) {
 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");

	return $query->rows;
} 

/**
 * End Daisycon Conversion Pixel for OpenCart
 */