Skip to content

Instantly share code, notes, and snippets.

@uabaluua
Created July 6, 2016 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uabaluua/05d3ca6418e07803959fc0666a30de4d to your computer and use it in GitHub Desktop.
Save uabaluua/05d3ca6418e07803959fc0666a30de4d to your computer and use it in GitHub Desktop.
<?php
/**
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2015 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class Remarketing extends Module
{
protected $config_form = false;
public function __construct()
{
$this->name = 'remarketing';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'UAWEB';
$this->need_instance = 1;
/**
* Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
*/
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Remarketing');
$this->description = $this->l('Add remarketing code to the page.');
$this->confirmUninstall = $this->l('');
}
/**
* Don't forget to create update methods if needed:
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
*/
public function install()
{
Configuration::updateValue('REMARKETING_LIVE_MODE', false);
include(dirname(__FILE__).'/sql/install.php');
return parent::install() &&
$this->registerHook('header') &&
$this->registerHook('backOfficeHeader') &&
$this->registerHook('displayFooter');
}
public function uninstall()
{
Configuration::deleteByName('REMARKETING_LIVE_MODE');
include(dirname(__FILE__).'/sql/uninstall.php');
return parent::uninstall();
}
/**
* Load the configuration form
*/
public function getContent()
{
/**
* If values have been submitted in the form, process.
*/
if (((bool)Tools::isSubmit('submitRemarketingModule')) == true) {
$this->postProcess();
}
$this->context->smarty->assign('module_dir', $this->_path);
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
return $output.$this->renderForm();
}
/**
* Create the form that will be displayed in the configuration of your module.
*/
protected function renderForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitRemarketingModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array($this->getConfigForm()));
}
/**
* Create the structure of your form.
*/
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Live mode'),
'name' => 'REMARKETING_LIVE_MODE',
'is_bool' => true,
'desc' => $this->l('Use this module in live mode'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
),
array(
'col' => 3,
'type' => 'text',
'prefix' => '<i class="icon icon-envelope"></i>',
'desc' => $this->l('Enter a valid email address'),
'name' => 'REMARKETING_ACCOUNT_EMAIL',
'label' => $this->l('Email'),
),
array(
'type' => 'password',
'name' => 'REMARKETING_ACCOUNT_PASSWORD',
'label' => $this->l('Password'),
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}
/**
* Set values for the inputs.
*/
protected function getConfigFormValues()
{
return array(
'REMARKETING_LIVE_MODE' => Configuration::get('REMARKETING_LIVE_MODE', true),
'REMARKETING_ACCOUNT_EMAIL' => Configuration::get('REMARKETING_ACCOUNT_EMAIL', 'contact@prestashop.com'),
'REMARKETING_ACCOUNT_PASSWORD' => Configuration::get('REMARKETING_ACCOUNT_PASSWORD', null),
);
}
/**
* Save form data.
*/
protected function postProcess()
{
$form_values = $this->getConfigFormValues();
foreach (array_keys($form_values) as $key) {
Configuration::updateValue($key, Tools::getValue($key));
}
}
/**
* Add the CSS & JavaScript files you want to be loaded in the BO.
*/
public function hookBackOfficeHeader()
{
if (Tools::getValue('module_name') == $this->name) {
$this->context->controller->addJS($this->_path.'views/js/back.js');
$this->context->controller->addCSS($this->_path.'views/css/back.css');
}
}
/**
* Add the CSS & JavaScript files you want to be added on the FO.
*/
public function hookHeader()
{
$this->context->controller->addJS($this->_path.'/views/js/front.js');
$this->context->controller->addCSS($this->_path.'/views/css/front.css');
}
public function hookDisplayFooter()
{
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$script_first_part = "<script type=\"text/javascript\"> var google_tag_params = { dynx_itemid: ";
$script_second_part = ", dynx_pagetype: 'product', dynx_totalvalue: ";
$script_third_part = "};</script><script type=\"text/javascript\"> /*<![CDATA[*/ var google_conversion_id = 880765089;var google_custom_params = window.google_tag_params;var google_remarketing_only = true; /*]]>*/ </script><script type=\"text/javascript\" src=\"//www.googleadservices.com/pagead/conversion.js\"></script><noscript><div><img height=\"1\" width=\"1\" alt=\"\" src=\"//googleads.g.doubleclick.net/pagead/viewthroughconversion/";
$script_fourth_part = "/?value=0&guid=ON&script=0";
$script_fifth_part = "\"/></div></noscript>";
$script_itemid = 0;
$script_totalvalue = 0;
$script_link = 0;
switch ($actual_link) {
case "http://divesco-trade.com.ua/printery-chekov-pos-printery/11-termoprinter-dlya-chekov-s-avtoobrezkoj-xp-q200ii-80mm-lan-ili-usb-versii.html":
$script_itemid = 11;
$script_totalvalue = 3200;
break;
case "http://divesco-trade.com.ua/skanery-shtrikh-koda/16-ckaner-shtrikh-kodov-alanda-ls-007-s-funkciej-sbora-dannykh-besprovodnoj-.html":
$script_itemid = 16;
$script_totalvalue = 1500;
break;
case "http://divesco-trade.com.ua/printery-chekov-pos-printery/21-termoprinter-chekov-s-avtoobrezkoj-xp-t58nc-58mm-usb-versii.html":
$script_itemid = 21;
$script_totalvalue = 2500;
break;
case "http://divesco-trade.com.ua/printery-chekov-pos-printery/10-termoprinter-printer-dlya-chekov-jp-5890k.html":
$script_itemid = 10;
$script_totalvalue = 1500;
break;
case "http://divesco-trade.com.ua/skanery-shtrikh-koda/14-provodnoj-lazernyj-skaner-shtrikh-kodov-jepod-a1.html":
$script_itemid = 14;
$script_totalvalue = 850;
break;
case "http://divesco-trade.com.ua/skanery-shtrikh-koda/20-bluetooth-skaner-shtrikh-kodov-hero-je-h220b.html":
$script_itemid = 20;
$script_totalvalue = 2400;
break;
case "http://divesco-trade.com.ua/printery-etiketok-shtrikh-koda/9-termoprinter-dlya-pechati-etiketok-i-chekov-2-v-1-xp-360b.html":
$script_itemid = 9;
$script_totalvalue = 3300;
break;
case "http://divesco-trade.com.ua/printery-etiketok-shtrikh-koda/22-termoprinter-xprinter-370b-dlya-pechati-etiketoks-otdeleniem-etiketok.html":
$script_itemid = 22;
$script_totalvalue = 3900;
break;
case "http://divesco-trade.com.ua/resheniya-dlya-avtomatizacii/25-printer-chekov-5890k-skaner-jp-a1.html":
$script_itemid = 25;
$script_totalvalue = 2250;
break;
case "http://divesco-trade.com.ua/resheniya-dlya-avtomatizacii/26-akciya-printer-skaner.html":
$script_itemid = 26;
$script_totalvalue = 2600;
break;
case "http://divesco-trade.com.ua/resheniya-dlya-avtomatizacii/27-akciya-printer-chekov-5890k-skaner-jp-a1-printer-etiketok-xp-360b.html":
$script_itemid = 27;
$script_totalvalue = 5500;
break;
case "http://divesco-trade.com.ua/resheniya-dlya-avtomatizacii/38-printer-chekov-5890k-skaner-alanda-ls-007-printer-etiketok-xp-360b.html":
$script_itemid = 38;
$script_totalvalue = 6600;
break;
default:
$script_itemid = 'REPLACE_WITH_VALUE';
$script_totalvalue = 'REPLACE_WITH_VALUE';
break;
}
if ($script_itemid == 'REPLACE_WITH_VALUE'){
$script_link = 880765089;
$script_second_part = "', dynx_pagetype: 'REPLACE_WITH_VALUE',ecomm_prodid: 'REPLACE_WITH_VALUE', ecomm_pagetype: 'REPLACE_WITH_VALUE', ecomm_totalvalue: 'REPLACE_WITH_VALUE', dynx_totalvalue: '";
} else {
$script_link = $script_itemid;
}
$script_link = 880765089;
$datavalues = "&amp;data.dynx_itemid=" .$script_itemid . "&amp;data.dynx_pagetype=product&amp;data.dynx_totalvalue=" . $script_totalvalue;
return $script_first_part . $script_itemid . $script_second_part . $script_totalvalue . $script_third_part . $script_link . $script_fourth_part . $script_fifth_part;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment