name = 'antadismarketing'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'Antadis'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Antadis Marketing'); $this->description = $this->l('Antadis Marketing Tools'); $this->confirmUninstall = $this->l('Are you sure ?'); $this->l('Category Tracking'); $this->l('Cout'); $this->l('Cout par visite'); $this->l('Visits'); $this->l('Cout par inscription'); $this->l('Subscribe'); $this->l('Cout par commande'); $this->l('Total order'); $this->l('Total amount'); $this->l('Cout pour 1€ CA'); $this->l('Cout pour 1€ Marge'); $this->l('Average order'); $this->l('Total HT'); $this->l('Total supplier buy'); $this->l('Rate amount'); $this->l('Rate'); } public function install(){ if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); if (!parent::install() || !$this->registerHook('actionCustomerAccountAdd') || !$this->registerHook('actionValidateOrder') || !$this->registerHook('displayHeader') || !$this->registerHook('ModuleRoutes')) return false; $res = Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_tracking` ( `id_tracking` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `duree` tinyint(4) NOT NULL, `redirect` int(11) NOT NULL, `redirect_page` text NOT NULL, `redirection` varchar(450) NOT NULL, `subscribe_save` int(11) NOT NULL, `subscribe_tag` text NOT NULL, `cout` float(10,4) NOT NULL, `id_tracking_categories` int(11) NOT NULL, `date_add` date NOT NULL, `date_first_join` date NOT NULL, PRIMARY KEY (`id_tracking`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'); if ($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_tracking_lang` ( `id_tracking` int(11) NOT NULL, `id_lang` int(11) NOT NULL, `description` VARCHAR(255) NOT NULL, PRIMARY KEY(`id_tracking`, `id_lang`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); if ($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_tracking_categories` ( `id_tracking_categories` int(11) NOT NULL AUTO_INCREMENT, `id_parent_categories` int(11) NOT NULL, PRIMARY KEY (`id_tracking_categories`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); if ($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_tracking_categories_lang` ( `id_tracking_categories` int(11) NOT NULL, `id_lang` int(11) NOT NULL, `name` VARCHAR(255) NOT NULL, PRIMARY KEY(`id_tracking_categories`, `id_lang`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); if ($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_tracking_users` ( `id_tracking` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL, `date` date NOT NULL, PRIMARY KEY(`id_tracking`, `id_customer`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); if ($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_tracking_orders` ( `id_tracking` int(10) unsigned NOT NULL, `id_orders` int(10) unsigned NOT NULL, PRIMARY KEY(`id_tracking`, `id_orders`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); if ($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_tracking_visits` ( `id_tracking` int(10) unsigned NOT NULL, `date` date NOT NULL, `nb_visits` int(10) unsigned NOT NULL, PRIMARY KEY (`id_tracking`,`date`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); if ($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_referer` ( `referer_url` VARCHAR(255) NOT NULL, `nb_visits` int(10) unsigned NOT NULL, PRIMARY KEY(`referer_url`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); if($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_stats` ( `id_tracking` int(11) NOT NULL, `date` date NOT NULL, `total_products` int(11) NOT NULL, `total_order` int(11) NOT NULL, `total_products_price` float(10,4) NOT NULL, `total_products_price_tax_excl` float(10,4) NOT NULL, `total_wholesale_price` float(10,4) NOT NULL, `rate_amount` float(10,4) NOT NULL, `rate` float(10,4) NOT NULL, `subscribe` int(11) NOT NULL, `visits` int(11) NOT NULL, `cout_visits` float(10,4) NOT NULL, `cout_subscribe` float(10,4) NOT NULL, `cout_order` float(10,4) NOT NULL, `average_order` float(10,4) NOT NULL ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'); if($res) $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_marketing_stats_category` ( `id_tracking_category` int(11) NOT NULL, `date` date NOT NULL, `total_products` int(11) NOT NULL, `total_order` int(11) NOT NULL, `total_products_price` float(10,4) NOT NULL, `total_products_price_tax_excl` float(10,4) NOT NULL, `total_wholesale_price` float(10,4) NOT NULL, `rate_amount` float(10,4) NOT NULL, `rate` int(11) NOT NULL, `subscribe` int(11) NOT NULL, `visits` int(11) NOT NULL, `cout` float(10,4) NOT NULL, `cout_order` float(10,4) NOT NULL, `cout_subscribe` float(10,4) NOT NULL, `cout_visit` float(10,4) NOT NULL ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'); if(!$res) return false; $res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'ant_marketing_referer` VALUES ("direct_access", 0)'); $res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'ant_marketing_tracking_categories` VALUES (1,0)'); $langs = Language::getLanguages(); foreach($langs as $l){ $res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'ant_marketing_tracking_categories_lang` VALUES (1 ,'. $l['id_lang'].', "Parent category")'); } if(!$res) return false; $this->createAdminTabs(); return true; } static function createTab($id_parent, $module, $name, $class_name) { $Tab = new Tab(); $Tab->module = $module; foreach(Language::getLanguages(true) as $languages) { $Tab->name[$languages["id_lang"]] = $name; } $Tab->id_parent = $id_parent; $Tab->class_name = $class_name; $r = $Tab->save(); if($r === false) return false; return $Tab->id; } private function createAdminTabs(){ $parent_tab = Db::getInstance()->getValue('SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE id_parent = 0 AND class_name = "AdminAntMarketing"'); if(!$parent_tab) $parent_tab = self::createTab(0, $this->name, 'Antadis Marketing', 'AdminAntMarketing'); self::createTab($parent_tab, $this->name, $this->l('Stats'), 'AdminAntMarketingStats'); self::createTab($parent_tab, $this->name, $this->l('Tracking'), 'AdminAntMarketingTracking'); self::createTab($parent_tab, $this->name, $this->l('Tracking Categories'), 'AdminAntMarketingTrackingCategories'); self::createTab($parent_tab, $this->name, $this->l('Referer URL'), 'AdminAntMarketingReferer'); } public function uninstall(){ $tables = array( 'ant_marketing_tracking', 'ant_marketing_tracking_lang', 'ant_marketing_tracking_categories', 'ant_marketing_tracking_categories_lang', 'ant_marketing_tracking_users', 'ant_marketing_tracking_orders', 'ant_marketing_tracking_visits', 'ant_marketing_referer', 'ant_marketing_stats', 'ant_marketing_stats_category' ); foreach($tables as $table) $res = Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.$table.'`'); if (!$res || !parent::uninstall()) return false; return true; } public function hookActionCustomerAccountAdd($params) { AntTracking::dispatchSubscribe($params['newCustomer']); return true; } public function hookActionValidateOrder($params) { AntTracking::dispatchOrder($params['order']->id); return true; } public function hookModuleRoutes($params) { //COMPATIBILITY WITH PRIVATESALE MODULE AntTracking::dispatchVisits(); return array(); } public function hookdisplayHeader($params) { // AntTracking::dispatchVisits(); return ''; } public function hookDisplayFooter($params) { return AntTracking::getSubscribeCode(); } } ?>