626 lines
24 KiB
PHP
626 lines
24 KiB
PHP
<?php
|
|
/**
|
|
* Module Criteo Tag et Flux Web In Color
|
|
*
|
|
* @author Web In Color - addons@webincolor.fr
|
|
* @version 2.6
|
|
* @uses Prestashop modules
|
|
* @since 1.0 - 22 juillet 2013
|
|
* @package criteo
|
|
* @copyright Copyright © 2014, Web In Color
|
|
* @license http://www.webincolor.fr
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
class Criteo_bbb extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'criteo_bbb';
|
|
$this->tab = 'advertising_marketing';
|
|
$this->version = '2.6';
|
|
$this->need_instance = 0;
|
|
$this->author = 'Web In Color';
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Criteo');
|
|
$this->description = $this->l('Criteo product export and tag display.');
|
|
|
|
/* Backward compatibility */
|
|
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
|
require(_PS_MODULE_DIR_.$this->name.'/backward_compatibility/backward.php');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
return (parent::install());/* && $this->registerHook('header')
|
|
&& $this->registerHook('productfooter')
|
|
&& $this->registerHook('home')
|
|
&& $this->registerHook('shoppingCartExtra')
|
|
&& $this->registerHook('footer')
|
|
&& $this->registerHook('orderConfirmation'));*/
|
|
}
|
|
|
|
private function postProcess()
|
|
{
|
|
if (Tools::isSubmit('submitCriteo'))
|
|
{
|
|
if (!Tools::getValue('id_criteo_account'))
|
|
return $this->displayError($this->l('All fields required'));
|
|
|
|
Configuration::updateValue('WIC_CRITEO_ID_ACCOUNT', pSQL(Tools::getValue('id_criteo_account')));
|
|
Configuration::updateValue('WIC_CRITEO_SITE_TYPE', pSQL(Tools::getValue('site_type_criteo')));
|
|
Configuration::updateValue('WIC_CRITEO_CATEGORY', (Tools::getValue('category') ? implode(',', Tools::getValue('category')) : ''));
|
|
Configuration::updateValue('WIC_CRITEO_DISPLAY_CAT', Tools::getValue('display_category_criteo'));
|
|
Configuration::updateValue('WIC_CRITEO_URL_MODE', pSQL(Tools::getValue('url_criteo_mode')));
|
|
|
|
return $this->displayConfirmation($this->l('Settings updated successfully'));
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
if (version_compare(_PS_VERSION_, '1.4', '>='))
|
|
$this->_html = '<link type="text/css" rel="stylesheet" href="'.$this->_path.'css/admin.css" />';
|
|
else
|
|
$this->_html = '<link type="text/css" rel="stylesheet" href="'.$this->_path.'css/admin_backward.css" />';
|
|
|
|
//$this->_html .= '<div class="toolbar-placeholder"><div class="toolbarBox toolbarHead"><div class="pageTitle"><h3> <span id="current_obj" style="font-weight: normal;"> <span class="breadcrumb item-0 "><img src="'.$this->_path.'img/logo_webincolor_L260.png" width="260" height="70"/>'.$this->l('Expertise e-commerce Prestashop').'</span> </span></h3><span class="readme"><img src="'.$this->_path.'img/PDF.png" width="32" height="32"/><a href="http://www.webincolor.fr/addons_prestashop/'.$this->l('criteo_en.pdf').'" target="_blank">'.$this->l('Download the documentation').'</a></span></div></div><div class="leadin"></div></div>';
|
|
|
|
if (version_compare(_PS_VERSION_, '1.5', '<='))
|
|
$this->_html .= '<script type="text/javascript" src="'.$this->_path.'js/toolbar.js"></script>';
|
|
|
|
$this->_html .= $this->postProcess();
|
|
|
|
$this->_html .= '
|
|
<fieldset>
|
|
<legend><img src="'.$this->_path.'logo.gif" alt="" title=""/> '.$this->l('Criteo Export').'</legend>
|
|
<form method="post" action="" name="criteoForm" id="criteo-wrapper">
|
|
<div class="warn alert alert-warning">
|
|
<span style="float:right">
|
|
<a id="hideWarn" href=""><img alt="X" src="../img/admin/close.png"></a>
|
|
</span>
|
|
<ul style="margin-top: 3px">
|
|
<li>'.$this->l('URL to communicate to Criteo:');
|
|
if (version_compare(_PS_VERSION_, '1.5', '>='))
|
|
{
|
|
$shops = Shop::getShops();
|
|
|
|
foreach ($shops as $shop)
|
|
$this->_html .= ' <a href="'.Tools::getProtocol().$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/'.$this->name.'/tools/export_xml.php?token='.sha1(_COOKIE_KEY_.'exportCriteo').'">'.Tools::getProtocol().$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/'.$this->name.'/tools/export_xml.php?id_shop='.$shop['id_shop'].'&token='.sha1(_COOKIE_KEY_.'exportCriteo').'</a></li>';
|
|
}
|
|
else
|
|
$this->_html .= ' <a href="'.Tools::getProtocol().$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/'.$this->name.'/tools/export_xml.php?token='.sha1(_COOKIE_KEY_.'exportCriteo').'">'.Tools::getProtocol().$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/'.$this->name.'/tools/export_xml.php?token='.sha1(_COOKIE_KEY_.'exportCriteo').'</a></li>';
|
|
|
|
$this->_html .= '</ul>
|
|
</div>
|
|
<label for="id_normal_criteo">'.$this->l('Criteo ID account').' :</label>
|
|
<input type="text" value="'.(Configuration::get('WIC_CRITEO_ID_ACCOUNT') ? Configuration::get('WIC_CRITEO_ID_ACCOUNT') : '').'" name="id_criteo_account" /><br /><br />
|
|
<label for="site_type_criteo">'.$this->l('Site type').' :</label>
|
|
<select name="site_type_criteo">
|
|
<option value="d" '.(Configuration::get('WIC_CRITEO_SITE_TYPE') == 'd' ? 'selected=selected' : '').'>'.$this->l('Classic website').'</option>
|
|
<option value="m" '.(Configuration::get('WIC_CRITEO_SITE_TYPE') == 'm' ? 'selected=selected' : '').'>'.$this->l('Mobile website').'</option>
|
|
<option value="t" '.(Configuration::get('WIC_CRITEO_SITE_TYPE') == 't' ? 'selected=selected' : '').'>'.$this->l('tablet website').'</option>
|
|
</select><br/><br/>
|
|
<label for="display_category_criteo">'.$this->l('Display Category produt in XML flow').' :</label>
|
|
<input type="radio" value="0" name="display_category_criteo" '.(Configuration::get('WIC_CRITEO_DISPLAY_CAT') ? '' : 'checked=checked').' /> No
|
|
<input type="radio" value="1" name="display_category_criteo" '.(Configuration::get('WIC_CRITEO_DISPLAY_CAT') ? 'checked=checked' : '').' /> Yes
|
|
<br/><br/>
|
|
<p></p>
|
|
<label for="url_criteo_mode">'.$this->l('Use url produt in XML flow').' :</label>
|
|
<input type="radio" value="0" name="url_criteo_mode" '.(Configuration::get('WIC_CRITEO_URL_MODE') ? '' : 'checked=checked').' /> No
|
|
<input type="radio" value="1" name="url_criteo_mode" '.(Configuration::get('WIC_CRITEO_URL_MODE') ? 'checked=checked' : '').' /> Yes
|
|
|
|
<br/><br/>';
|
|
|
|
/*
|
|
<div class="row">
|
|
<div class="warn alert alert-warning">
|
|
<ul style="margin-top: 3px">
|
|
<li>'.$this->l('You can exclude categories, so that the products are not present.').'</li>
|
|
<li><strong>'.$this->l('Warning !').'</strong> '.$this->l('Products with the default category is selected below will not be exported.').'</li>
|
|
</ul>
|
|
</div>
|
|
<table style="width: 32em;float:left;"><tr><td>
|
|
<h4>'.$this->l('Category filter').'</h4>
|
|
<table cellspacing="0" cellpadding="0" class="table" style="width: 29.5em;">
|
|
<tr>
|
|
<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'category[]\', this.checked)" /></th>
|
|
<th>'.$this->l('ID').'</th>
|
|
<th>'.$this->l('Name').'</th>
|
|
</tr>';
|
|
$done = array();
|
|
$index = array();
|
|
$indexed_categories = explode(',', Configuration::get('WIC_CRITEO_CATEGORY'));
|
|
$categories = Category::getCategories((int)$this->context->language->id, false);
|
|
foreach ($indexed_categories as $k => $row)
|
|
$index[] = $row;
|
|
$this->recurseCategoryForInclude($index, $categories, $categories[0][1], 1, null, $done);
|
|
$this->_html .= '</table>
|
|
<p style="padding:0px; margin:0px 0px 10px 0px; color: #7F7F7F;font-size: 0.85em;"><i>'.$this->l('Mark all checkbox(es) of categories to which the product are not in data XML flow').'<sup> *</sup></i></p>
|
|
</td></tr>
|
|
</table>
|
|
</div>*/
|
|
$this->_html .= '<br clear="all" />
|
|
<div>
|
|
<center class="submit"><input type="submit" class="button" name="submitCriteo" value="'.$this->l('Submit').'" class="button" /></center>
|
|
</div>
|
|
</form>
|
|
</fieldset>';
|
|
|
|
//$this->_html .= '<iframe src="http://www.webincolor.fr/addons_prestashop.html" width="670" height="430" border="0"></iframe>';
|
|
|
|
return $this->_html;
|
|
}
|
|
|
|
/* Build a categories tree
|
|
*
|
|
* @param array $indexed_categories Array with categories where product is indexed (in order to check checkbox)
|
|
* @param array $categories Categories to list
|
|
* @param array $current Current category
|
|
* @param integer $id_category Current category id
|
|
*/
|
|
private function recurseCategoryForInclude($indexed_categories, $categories, $current, $id_category = 1, $id_category_default = null, $has_suite = array(), $done = array())
|
|
{
|
|
static $irow;
|
|
if (!isset($done[$current['infos']['id_parent']]))
|
|
$done[$current['infos']['id_parent']] = 0;
|
|
$done[$current['infos']['id_parent']] += 1;
|
|
|
|
$todo = count($categories[$current['infos']['id_parent']]);
|
|
$done_c = $done[$current['infos']['id_parent']];
|
|
|
|
$level = $current['infos']['level_depth'] + 1;
|
|
|
|
$this->_html .= '
|
|
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
|
<td>
|
|
<input type="checkbox" name="category[]" class="categoryBox'.($id_category_default != null ? ' id_category_default' : '').'" id="category_'.$id_category.'" value="'.$id_category.'"'.(((in_array($id_category, $indexed_categories) || ((int)Tools::getValue('id_category') == $id_category)) || Tools::getIsset('adddiscount')) ? ' checked="checked"' : '').' />
|
|
</td>
|
|
<td>
|
|
'.$id_category.'
|
|
</td>
|
|
<td>';
|
|
if (version_compare(_PS_VERSION_, '1.4', '>='))
|
|
{
|
|
for ($i = 2; $i < $level; $i++)
|
|
$this->_html .= '<img src="../img/admin/lvl_'.(isset($has_suite[$i - 2]) ? '' : '1').'.gif" alt="" style="vertical-align:middle!important;" />';
|
|
$this->_html .= '<img src="../img/admin/'.($level == 1 ? 'lv1.gif' : 'lv2_'.($todo == $done_c ? 'f' : 'b').'.gif').'" alt="" style="vertical-align:middle!important;" />
|
|
<label for="category_'.$id_category.'" class="t">'.$current['infos']['name'].'</label>';
|
|
}
|
|
else
|
|
{
|
|
$img = $level == 1 ? 'lv1.gif' : 'lv'.$level.'_'.($todo == $done_c ? 'f' : 'b').'.gif';
|
|
$this->_html .= '<img src="../img/admin/'.$img.'" alt="" style="vertical-align:middle!important;" /> <label for="category_'.$id_category.'" class="t">'.$current['infos']['name'].'</label>';
|
|
}
|
|
$this->_html .= '</td>
|
|
</tr>';
|
|
|
|
if ($level > 1)
|
|
$has_suite[] = ($todo == $done_c ? 0 : 1);
|
|
if (isset($categories[$id_category]))
|
|
foreach ($categories[$id_category] as $key => $row)
|
|
if ($key != 'infos')
|
|
$this->recurseCategoryForInclude($indexed_categories, $categories, $categories[$id_category][$key], $key, $has_suite, $done);
|
|
}
|
|
|
|
public function buildXML($id_shop=0)
|
|
{
|
|
set_time_limit(300);
|
|
|
|
$html = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<products>'."\n";
|
|
/* First line, columns */
|
|
$columns = array('id', 'name', 'smallimage', 'bigimage', 'producturl', 'description', 'price', 'retailprice', 'discount', 'recommendable', 'instock');
|
|
|
|
/* Setting parameters */
|
|
$conf = Configuration::getMultiple(array(
|
|
'PS_LANG_DEFAULT'));
|
|
|
|
$id_lang = (int)$conf['PS_LANG_DEFAULT'];
|
|
/* Searching for products */
|
|
$result = Db::getInstance()->executeS('
|
|
SELECT DISTINCT p.`id_product`, i.`id_image`, psl.`description` as `ps_description`
|
|
FROM `'._DB_PREFIX_.'product` p
|
|
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON p.`id_product` = c.`id_product`
|
|
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.id_product = p.id_product)
|
|
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.id_product = p.id_product)
|
|
LEFT JOIN `'._DB_PREFIX_.'privatesale` ps ON psc.`id_sale` = ps.`id_sale`
|
|
LEFT JOIN `'._DB_PREFIX_.'privatesale_site_version` psv ON psv.`id_sale` = ps.`id_sale`
|
|
LEFT JOIN `'._DB_PREFIX_.'privatesale_lang` psl ON psl.`id_sale` = ps.`id_sale`
|
|
WHERE ps.`date_start` < NOW()
|
|
AND ps.`date_end` > NOW()
|
|
AND ps.`enabled` = 1
|
|
AND ps.`id_sale` IS NOT NULL
|
|
AND psv.`version` = "fr"
|
|
AND p.`active` = 1
|
|
AND i.id_image IS NOT NULL
|
|
AND psl.`id_lang` = '.(int) $id_lang.'
|
|
ORDER BY ps.`id_sale`
|
|
');
|
|
foreach ($result as $k => $row)
|
|
{
|
|
if (Pack::isPack((int)$row['id_product']))
|
|
continue;
|
|
$product = new Product((int)$row['id_product'], true);
|
|
|
|
if (Validate::isLoadedObject($product))
|
|
{
|
|
$imageObj = Product::getCover((int)$product->id);
|
|
|
|
$line = array();
|
|
$line[] = htmlentities($product->name[$id_lang]);
|
|
|
|
$line[] = $this->context->link->getImageLink($product->link_rewrite[$id_lang], (version_compare(_PS_VERSION_, '1.5', '>=') ? $imageObj['id_image'] : $product->id.'-'.$imageObj['id_image']), (version_compare(_PS_VERSION_, '1.5', '>=')?ImageType::getFormatedName('small'):'small'));
|
|
$line[] = $this->context->link->getImageLink($product->link_rewrite[$id_lang], (version_compare(_PS_VERSION_, '1.5', '>=') ? $imageObj['id_image'] : $product->id.'-'.$imageObj['id_image']), (version_compare(_PS_VERSION_, '1.5', '>=')?ImageType::getFormatedName('small'):'thickbox'));
|
|
|
|
$line[] = $this->context->link->getProductLink((int)$product->id, $product->link_rewrite[$id_lang], $product->ean13).'?utm_source=criteo&aff=criteo';
|
|
|
|
$line[] = str_replace(array("\n", "\r", "\t", '|'), '', strip_tags(html_entity_decode($row['ps_description'], ENT_COMPAT, 'UTF-8')));
|
|
|
|
$price = $product->getPrice(true, (int)Product::getDefaultAttribute($product->id));
|
|
|
|
if ($product->getPrice(true, (int)Product::getDefaultAttribute((int)$product->id), 6, null, false, false)) {
|
|
$val = $product->getPrice(true, (int)Product::getDefaultAttribute((int)$product->id), 6, null, false, false);
|
|
} else {
|
|
$val = 1;
|
|
}
|
|
|
|
$line[] = number_format($price, 2, '.', '');
|
|
$line[] = number_format($product->getPrice(true, (int)Product::getDefaultAttribute((int)$product->id), 6, null, false, false), 2, '.', '');
|
|
$line[] = number_format($product->getPrice(true, null, 2, null, true) * 100 / $val, 2, '.', '');
|
|
$line[] = '1';
|
|
$line[] = '1';
|
|
|
|
$cpt_xml = 1;
|
|
$html .= "\t".'<product id="'.$product->id.'">'."\n";
|
|
foreach ($line as $column)
|
|
{
|
|
$html .= "\t\t".'<'.$columns[$cpt_xml].'>'.$column.'</'.$columns[$cpt_xml].'>'."\n";
|
|
$cpt_xml++;
|
|
}
|
|
|
|
if (Configuration::get('WIC_CRITEO_DISPLAY_CAT'))
|
|
{
|
|
$categories = Product::getProductCategoriesFull((int)$product->id, $id_lang);
|
|
if ($categories)
|
|
{
|
|
$i = 1;
|
|
foreach ($categories as $category)
|
|
{
|
|
$html .= '<category_'.$i.'>'.$category['name'].'</category_'.$i.'>'."\n";
|
|
$i++;
|
|
}
|
|
}
|
|
}
|
|
|
|
$html .= "\t".'</product>'."\n";
|
|
}
|
|
}
|
|
$html .= '</products>'."\n";
|
|
echo $html;
|
|
}
|
|
|
|
public function fetchTemplate($path, $name, $extension = false)
|
|
{
|
|
return $this->display(__FILE__, $path.$name.'.'.($extension ? $extension : 'tpl'));
|
|
}
|
|
|
|
public function hookProductFooter($params)
|
|
{
|
|
global $site_version;
|
|
|
|
if(!isset($site_version) || $site_version != 'com') {
|
|
return;
|
|
}
|
|
|
|
if (!Configuration::get('WIC_CRITEO_ID_ACCOUNT') || !Configuration::get('WIC_CRITEO_SITE_TYPE')) {
|
|
return false;
|
|
}
|
|
|
|
if ($this->context->customer && $this->context->customer->id) {
|
|
$email = $this->context->customer->email;
|
|
} else {
|
|
$email = '';
|
|
}
|
|
|
|
|
|
$this->context->smarty->assign(array(
|
|
'wic_criteo_account' => Configuration::get('WIC_CRITEO_ID_ACCOUNT'),
|
|
'wic_criteo_site_type' => Configuration::get('WIC_CRITEO_SITE_TYPE'),
|
|
'wic_product_id' => (int) Tools::getValue('id_product'),
|
|
'wic_action' => 'productFooter',
|
|
'id_customer' => $this->context->customer? $this->context->customer->id: 0,
|
|
'customer_email' => ($email) ? md5($email) : '',
|
|
'is_newsletter' => isset($_COOKIE['emst']) || (bool) Tools::getValue('emst'),
|
|
));
|
|
|
|
return $this->fetchTemplate('/views/templates/hooks/', 'criteo');
|
|
}
|
|
|
|
public function hookShoppingCartExtra($params)
|
|
{
|
|
global $site_version;
|
|
|
|
if(!isset($site_version) || $site_version != 'com') {
|
|
return;
|
|
}
|
|
|
|
if (!Configuration::get('WIC_CRITEO_ID_ACCOUNT') || !Configuration::get('WIC_CRITEO_SITE_TYPE'))
|
|
return false;
|
|
|
|
|
|
$strproducts = '';
|
|
|
|
$id_products = array();
|
|
foreach($params['products'] as $delay) {
|
|
foreach ($delay['products'] as $product) {
|
|
$id_products[] = (int) $product['id_product'];
|
|
}
|
|
}
|
|
$products_sales = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT `id_product`, `id_sale`
|
|
FROM `'._DB_PREFIX_.'product_ps_cache`
|
|
WHERE `id_product` IN ('.implode(', ', $id_products).')
|
|
AND `id_sale` != 0
|
|
') as $row) {
|
|
$products_sales[(int) $row['id_product']] = (int) $row['id_product'];
|
|
}
|
|
|
|
if(count($products_sales) == 0) {
|
|
return;
|
|
}
|
|
|
|
$product_result = array();
|
|
|
|
foreach($params['products'] as $delay) {
|
|
foreach ($delay['products'] as $product) {
|
|
if(isset($products_sales[(int) $product['id_product']])) {
|
|
if(!isset($product_result[$products_sales[(int) $product['id_product']]])) {
|
|
$product_result[$products_sales[(int) $product['id_product']]]['price'] = 0;
|
|
$product_result[$products_sales[(int) $product['id_product']]]['quantity'] = 0;
|
|
}
|
|
$product_obj = new Product((int)$product['id_product']);
|
|
$price = $product_obj->getPrice(true, ($product['id_product_attribute'] ? $product['id_product_attribute'] : (int)Product::getDefaultAttribute($product_obj->id)), 2);
|
|
$product_result[$products_sales[(int) $product['id_product']]]['price'] += $price * (int) $product['quantity'];
|
|
$product_result[$products_sales[(int) $product['id_product']]]['quantity'] += (int) $product['quantity'];
|
|
unset($product_obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach($product_result as $id_product => $value) {
|
|
$strproducts .= '{ id: '.$id_product.', price: '.$value['price'].', quantity: '.$value['quantity'].' },';
|
|
}
|
|
|
|
$strproducts = Tools::substr($strproducts, 0, -1);
|
|
|
|
if ($this->context->customer && $this->context->customer->id) {
|
|
$email = $this->context->customer->email;
|
|
} else {
|
|
$email = '';
|
|
}
|
|
|
|
$this->context->smarty->assign(array(
|
|
'wic_criteo_account' => Configuration::get('WIC_CRITEO_ID_ACCOUNT'),
|
|
'wic_criteo_site_type' => Configuration::get('WIC_CRITEO_SITE_TYPE'),
|
|
'wic_product_list' => rtrim($strproducts, ','),
|
|
'wic_action' => 'shoppingCart',
|
|
'id_customer' => $this->context->customer? $this->context->customer->id: 0,
|
|
'customer_email' => ($email) ? md5($email) : '',
|
|
));
|
|
|
|
return $this->fetchTemplate('/views/templates/hooks/', 'criteo');
|
|
}
|
|
|
|
public function hookNewOrder($params) {
|
|
return $this->hookOrderConfirmation($params);
|
|
}
|
|
|
|
public function hookOrderConfirmation($params)
|
|
{
|
|
global $site_version;
|
|
|
|
if(!isset($site_version) || $site_version != 'com') {
|
|
return;
|
|
}
|
|
|
|
if (!Configuration::get('WIC_CRITEO_ID_ACCOUNT') || !Configuration::get('WIC_CRITEO_SITE_TYPE')) {
|
|
return false;
|
|
}
|
|
|
|
if(isset($params['objOrder'])) {
|
|
$cart = new Cart((int)$params['objOrder']->id_cart);
|
|
} elseif(isset($params['cart']) && Validate::isLoadedObject($params['cart'])) {
|
|
$cart = $params['cart'];
|
|
} else {
|
|
return;
|
|
}
|
|
$products = $cart->getProducts();
|
|
$strproducts = '';
|
|
|
|
$id_products = array();
|
|
foreach ($products as $product) {
|
|
$id_products[] = (int) $product['id_product'];
|
|
}
|
|
$products_sales = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT `id_product`, `id_sale`
|
|
FROM `'._DB_PREFIX_.'product_ps_cache`
|
|
WHERE `id_product` IN ('.implode(', ', $id_products).')
|
|
AND `id_sale` != 0
|
|
') as $row) {
|
|
$products_sales[(int) $row['id_product']] = (int) $row['id_product'];
|
|
}
|
|
|
|
if(count($products_sales) == 0) {
|
|
return;
|
|
}
|
|
|
|
$product_result = array();
|
|
|
|
foreach ($products as $product) {
|
|
if(isset($products_sales[$product['id_product']])) {
|
|
if(!isset($product_result[$products_sales[$product['id_product']]])) {
|
|
$product_result[$products_sales[$product['id_product']]]['price'] = 0;
|
|
$product_result[$products_sales[$product['id_product']]]['quantity'] = 0;
|
|
}
|
|
$product_obj = new Product((int)$product['id_product']);
|
|
$price = $product_obj->getPrice(true, ($product['id_product_attribute'] ? $product['id_product_attribute'] : (int)Product::getDefaultAttribute($product_obj->id)), 2);
|
|
$product_result[$products_sales[$product['id_product']]]['price'] += $price * (int) $product['quantity'];
|
|
$product_result[$products_sales[$product['id_product']]]['quantity'] += (int) $product['quantity'];
|
|
unset($product_obj);
|
|
}
|
|
}
|
|
|
|
foreach($product_result as $id_product => $value) {
|
|
$strproducts .= '{ id: '.$id_product.', price: '.$value['price'].', quantity: '.$value['quantity'].' },';
|
|
}
|
|
|
|
$strproducts = Tools::substr($strproducts, 0, -1);
|
|
|
|
/*$customer = new Customer($this->context->customer->id);*/
|
|
|
|
$new = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
|
SELECT COUNT(`id_order`) FROM `'._DB_PREFIX_.'orders` o
|
|
WHERE o.valid = 1 AND o.`id_customer` = '.(int) ($this->context->customer? $this->context->customer->id: 0));
|
|
|
|
$this->context->smarty->assign(array(
|
|
'wic_criteo_account' => Configuration::get('WIC_CRITEO_ID_ACCOUNT'),
|
|
'wic_criteo_site_type' => Configuration::get('WIC_CRITEO_SITE_TYPE'),
|
|
'wic_product_list' => rtrim($strproducts, ','),
|
|
'wic_action' => 'orderConfirmation',
|
|
'wic_id_order' => (int) $cart->id,
|
|
'id_customer' => $this->context->customer? $this->context->customer->id: 0,
|
|
'old_customer' => (($new > 1) ? '1' : '0'),
|
|
'customer_email' => ($this->context->customer) ? md5($this->context->customer->email) : '',
|
|
));
|
|
|
|
return $this->fetchTemplate('/views/templates/hooks/', 'criteo');
|
|
}
|
|
|
|
public function hookHeader($params)
|
|
{
|
|
global $site_version, $page_name;
|
|
|
|
// if($page_name != 'order' && $page_name != 'order-confirmation' && $page_name != 'submit') {
|
|
// return;
|
|
// }
|
|
|
|
if(!isset($site_version) || $site_version != 'com') {
|
|
return;
|
|
}
|
|
|
|
if (!Configuration::get('WIC_CRITEO_ID_ACCOUNT') || !Configuration::get('WIC_CRITEO_SITE_TYPE'))
|
|
return false;
|
|
|
|
return '<script type="text/javascript" src="//static.criteo.com/js/ld/ld.js" async="true"></script>';
|
|
}
|
|
|
|
public function hookHome($params)
|
|
{
|
|
|
|
global $site_version;
|
|
|
|
if(!isset($site_version) || $site_version != 'com') {
|
|
return;
|
|
}
|
|
|
|
if (!Configuration::get('WIC_CRITEO_ID_ACCOUNT') || !Configuration::get('WIC_CRITEO_SITE_TYPE'))
|
|
return false;
|
|
|
|
if ($this->context->customer && $this->context->customer->id) {
|
|
$email = $this->context->customer->email;
|
|
} else {
|
|
$email = '';
|
|
}
|
|
|
|
$this->context->smarty->assign(array(
|
|
'wic_criteo_account' => Configuration::get('WIC_CRITEO_ID_ACCOUNT'),
|
|
'wic_criteo_site_type' => Configuration::get('WIC_CRITEO_SITE_TYPE'),
|
|
'wic_action' => 'home',
|
|
'id_customer' => $this->context->customer? $this->context->customer->id: 0,
|
|
'customer_email' => ($email) ? md5($email) : '',
|
|
));
|
|
|
|
return $this->fetchTemplate('/views/templates/hooks/', 'criteo');
|
|
}
|
|
|
|
public function hookFooter($params)
|
|
{
|
|
global $site_version;
|
|
|
|
if(!isset($site_version) || $site_version != 'com') {
|
|
return;
|
|
}
|
|
|
|
if (!Configuration::get('WIC_CRITEO_ID_ACCOUNT') || !Configuration::get('WIC_CRITEO_SITE_TYPE')) {
|
|
return false;
|
|
}
|
|
|
|
if (Tools::getValue('id_category')) {
|
|
|
|
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
|
SELECT cp.`id_product`
|
|
FROM `'._DB_PREFIX_.'product` p
|
|
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`
|
|
WHERE cp.`id_category` = '.(int)Tools::getValue('id_category').'
|
|
AND p.`active` = 1 ORDER BY cp.`position`
|
|
LIMIT 3
|
|
');
|
|
|
|
if ($this->context->customer && $this->context->customer->id) {
|
|
$email = $this->context->customer->email;
|
|
} else {
|
|
$email = '';
|
|
}
|
|
|
|
$this->context->smarty->assign(array(
|
|
'wic_criteo_account' => Configuration::get('WIC_CRITEO_ID_ACCOUNT'),
|
|
'wic_criteo_site_type' => Configuration::get('WIC_CRITEO_SITE_TYPE'),
|
|
'wic_action' => 'productList',
|
|
'id_customer' => $this->context->customer? $this->context->customer->id: 0,
|
|
'customer_email' => ($email) ? md5($email) : '',
|
|
));
|
|
|
|
if (isset($products)) {
|
|
$products_data = array();
|
|
foreach ($products as $product) {
|
|
$products_data[] = (int)$product['id_product'];
|
|
}
|
|
|
|
$this->context->smarty->assign(array('products_data' => implode(',', $products_data)));
|
|
}
|
|
|
|
return $this->fetchTemplate('/views/templates/hooks/', 'criteo');
|
|
|
|
} elseif (Tools::getValue('search_query')) {
|
|
|
|
if ($this->context->customer && $this->context->customer->id)
|
|
{
|
|
$email = $this->context->customer->email;
|
|
} else {
|
|
$email = '';
|
|
}
|
|
|
|
$this->context->smarty->assign(array(
|
|
'wic_criteo_account' => Configuration::get('WIC_CRITEO_ID_ACCOUNT'),
|
|
'wic_criteo_site_type' => Configuration::get('WIC_CRITEO_SITE_TYPE'),
|
|
'wic_action' => 'search',
|
|
'id_customer' => $this->context->customer? $this->context->customer->id: 0,
|
|
'customer_email' => ($email) ? md5($email) : '',
|
|
'searchQuery' => Tools::getValue('search_query'),
|
|
));
|
|
|
|
return $this->fetchTemplate('/views/templates/hooks/', 'criteo');
|
|
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|