name = 'privatesales_tools'; $this->tab = 'others'; $this->version = '0.1'; $this->author = 'Antadis'; $this->need_instance = 0; $this->module_key = ""; parent::__construct($name, $context); $this->displayName = $this->l('Private sale tools'); $this->description = $this->l('Private sale tools : stats, logistique, etc...'); $this->confirmUninstall = $this->l('are you sur to uninstall ?'); $this->currentIndex = 'index.php?controller=AdminModules'; $this->base_config_url = $this->currentIndex .'&configure=' . $this->name . '&token=' . Tools::getValue('token'); } public function install() { if (!parent::install() || !$this->installDb() || !$this->installTab()){ $this->uninstall(); return false; } return true; } public function installDb() { //MULTI CREATE A TESTER try { Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_logistique_export` ( `id_privatesales_export` int(11) NOT NULL AUTO_INCREMENT, `id_sale` int(11) NOT NULL, `status` varchar(150) NOT NULL, `from` datetime NOT NULL, `to` datetime NOT NULL, `date_add` datetime NOT NULL, PRIMARY KEY (`id_privatesales_export`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_stats_order` ( `id_sale` int(11) NOT NULL, `date` date NOT NULL, `total_order` int(11) NOT NULL, `total_products` int(11) NOT NULL, `total_products_price` float(10,4) NOT NULL, `total_products_price_tax_excl` float(10,4) NOT NULL, `total_shipping` float(10,4) NOT NULL, `total_wholesale_price` float NOT NULL, `rate_amount` float(10,4) NOT NULL, `rate` float(10,4) NOT NULL, KEY `annee` (`date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_stats_order_global` ( `id_sale` int(11) NOT NULL, `total_products` int(11) NOT NULL, `total_products_price` float(10,4) NOT NULL, `total_products_price_tax_excl` float(10,4) NOT NULL, `total_shipping` 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 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_stats_other` ( `name` varchar(150) NOT NULL, `date` date NOT NULL, `value` float(10,4) NOT NULL, `value_txt` text NOT NULL, PRIMARY KEY (`name`,`date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_stats_products` ( `id_sale` int(11) NOT NULL, `date` date NOT NULL, `product_id` int(11) NOT NULL, `product_attribute_id` int(11) NOT NULL, `reference` varchar(150) NOT NULL, `supplier_reference` varchar(150) NOT NULL, `name` varchar(250) NOT NULL, `total_products` int(11) NOT NULL, `total_products_price` float(10,4) NOT NULL, `total_products_price_tax_excl` float(10,4) NOT NULL, `total_products_wholesale_price` float(10,4) NOT NULL, `rate_amount` float(10,4) NOT NULL, `rate` float(10,4) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_stats_states` ( `id_privatesale_stats_states` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(150) NOT NULL, PRIMARY KEY (`id_privatesale_stats_states`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_stats_states_states` ( `id_privatesale_stats_states` int(11) NOT NULL, `id_order_state` int(11) NOT NULL, PRIMARY KEY (`id_privatesale_stats_states`,`id_order_state`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); return true; } catch(Exception $e) { return false; } } public function installTab() { $parent_tab = Db::getInstance()->getValue('SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE id_parent = 0 AND class_name = "AdminPrivateSales"'); if(!$parent_tab) $parent_tab = 9; //CATALOG TAB if(!self::createTab($parent_tab, $this->name, 'Stats', 'AdminPrivatesalesStats')) return false; if(!self::createTab($parent_tab, $this->name, 'Logistique', 'AdminPrivatesalesLogistique')) return false; 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; } /** * * @return boolean */ public function uninstall() { if(!parent::uninstall()){ return false; } return true; } }