* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7541 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class Criteo extends Module { public function __construct() { $this->name = 'criteo'; $this->tab = 'advertising_marketing'; $this->version = '1.0'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Criteo'); $this->description = $this->l('Criteo product export and tag display.'); } public function install() { return (parent::install() AND $this->registerHook('header') AND $this->registerHook('productfooter') AND $this->registerHook('home') AND $this->registerHook('shoppingCartExtra') AND $this->registerHook('orderConfirmation')); } public function uninstall() { return parent::uninstall(); } private function _postProcess() { $isUpdated = false; if (Tools::getValue('id_criteo_conversion')) { Configuration::updateValue('CRITEO_ID_CONVERSION', pSQL(Tools::getValue('id_criteo_conversion'))); $isUpdated = true; } if (Tools::getValue('id_criteo_normal')) { Configuration::updateValue('CRITEO_ID_NORMAL', pSQL(Tools::getValue('id_criteo_normal'))); $isUpdated = true; } if (Tools::getValue('url_widget_criteo')) { Configuration::updateValue('CRITEO_URL_WIDGET', pSQL(Tools::getValue('url_widget_criteo'))); $isUpdated = true; } if ($isUpdated) return true; return false; } public function getContent() { return '
'; } private static function getAllSubCats(&$all_cats, $id_cat, $id_lang) { $category = new Category(intval($id_cat)); $sub_cats = $category->getSubcategories($id_lang); if (count($sub_cats) > 0) foreach ($sub_cats AS $sub_cat) { $all_cats[] = $sub_cat['id_category']; self::getAllSubCats($all_cats, $sub_cat['id_category'], $id_lang); } } public static function buildCSV() { global $cookie, $country_infos; $cookie = new Cookie('ps'); $country_infos = array('id_group' => 0, 'id_tax' => 1); $html = ''; /* First line, columns */ $columns = array('id', 'name', 'smallimage', 'bigimage', 'producturl', 'description', 'price', 'retailprice', 'discount', 'recommendable', 'instock'); foreach ($columns AS $column) $html .= $column.'|'; $html = rtrim($html, '|')."\n"; /* Setting parameters */ $conf = Configuration::getMultiple(array( 'PS_REWRITING_SETTINGS', 'PS_LANG_DEFAULT', 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT', 'PS_COUNTRY_DEFAULT', 'PS_SHOP_NAME', 'PS_CURRENCY_DEFAULT', 'PS_CARRIER_DEFAULT')); /* Language */ $language = new Language(intval($conf['PS_LANG_DEFAULT'])); /* Link instance for products links */ $link = new Link(); $result = Db::getInstance()->ExecuteS(' SELECT DISTINCT p.`id_product`, i.`id_image` FROM `'._DB_PREFIX_.'product` p 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) WHERE p.`active` = 1 AND i.id_image IS NOT NULL GROUP BY p.id_product'); foreach ($result AS $k => $row) { if (Pack::isPack(intval($row['id_product']))) continue; $product = new Product(intval($row['id_product']), true); if (Validate::isLoadedObject($product)) { $imageObj = new Image($row['id_image']); $line = array(); $line[] = $product->id; $line[] = $product->manufacturer_name.' - '.$product->name[intval($conf['PS_LANG_DEFAULT'])]; $line[] = Tools::getProtocol().$_SERVER['HTTP_HOST']._THEME_PROD_DIR_.$imageObj->getExistingImgPath().'-small.jpg'; $line[] = Tools::getProtocol().$_SERVER['HTTP_HOST']._THEME_PROD_DIR_.$imageObj->getExistingImgPath().'-thickbox.jpg'; $line[] = $link->getProductLink(intval($product->id), $product->link_rewrite[intval($conf['PS_LANG_DEFAULT'])], $product->ean13).'&utm_source=criteo&aff=criteo'; $line[] = str_replace(array("\n", "\r", "\t", '|'), '', strip_tags(html_entity_decode($product->description_short[intval($conf['PS_LANG_DEFAULT'])], ENT_COMPAT, 'UTF-8'))); $price = $product->getPrice(true, intval(Product::getDefaultAttribute($product->id))); $line[] = number_format($price, 2, '.', ''); $line[] = number_format($product->getPrice(true, intval(Product::getDefaultAttribute(intval($product->id))), 6, NULL, false, false), 2, '.', ''); $line[] = $product->getPrice(true, NULL, 2, NULL, true); $line[] = '1'; $line[] = '1'; foreach ($line AS $column) $html .= trim($column).'|'; $html = rtrim($html, '|')."\n"; } } echo $html; } public static function buildXML() { global $cookie, $country_infos; $cookie = new Cookie('ps'); $country_infos = array('id_group' => 0, 'id_tax' => 1); $html = '