name = 'antadisconfigurator'; $this->tab = 'front_office_features'; $this->version = '0.1'; $this->author = 'antadis'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Product Options'); $this->description = $this->l('Add options on product'); $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); $this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?'); } public function install() { // Call install parent method if (!parent::install()) { return false; } //Database $sql = array( "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."configurator_opt` ( `id_configurator_opt` int(11) unsigned NOT NULL AUTO_INCREMENT, `id_configurator_opt_group` int(11) NOT NULL, `price` decimal(20,6) NOT NULL DEFAULT '0.000000', `position` int(2) NOT NULL, PRIMARY KEY (`id_configurator_opt`), KEY `id_configurator_opt_values` (`id_configurator_opt`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Configurator options values';", "CREATE TABLE `"._DB_PREFIX_."configurator_opt_group_lang` ( `id_configurator_opt_group` int(11) NOT NULL, `id_lang` int(11) NOT NULL, `name` varchar(255) NOT NULL, `description` text NOT NULL, PRIMARY KEY (`id_configurator_opt_group`,`id_lang`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", "CREATE TABLE `"._DB_PREFIX_."configurator_opt_group` ( `id_configurator_opt_group` int(11) unsigned NOT NULL AUTO_INCREMENT, `type` varchar(20) NOT NULL, `reference` varchar(255) NOT NULL, PRIMARY KEY (`id_configurator_opt_group`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Configurator product options';", "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."configurator_opt_group_lang` ( `id_configurator_opt_group` int(11) NOT NULL, `id_lang` int(11) NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`id_configurator_opt_group`,`id_lang`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."configurator_storage` ( `id_configurator` int(11) unsigned NOT NULL DEFAULT '0', `id_product` int(11) NOT NULL, `id_configurator_opt_group` int(11) NOT NULL, `id_configurator_opt` int(11) NOT NULL, `opt_value` varchar(255) NOT NULL DEFAULT '', `price` decimal(20,6) NOT NULL, KEY `id_configurator` (`id_configurator`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", "CREATE TABLE `"._DB_PREFIX_."product_configurator_opt_group` ( `id_product_configurator_opt_group` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(11) NOT NULL, `id_configurator_opt_group` int(11) NOT NULL, `required` tinyint(1) NOT NULL, `visibility` tinyint(1) NOT NULL DEFAULT '1', `position` tinyint(1) NOT NULL, PRIMARY KEY (`id_product_configurator_opt_group`), UNIQUE KEY `id_product` (`id_product`,`id_configurator_opt_group`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;", "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."product_configurator_opt_impact` ( `id_product_configurator_opt_impact` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(11) NOT NULL, `id_product_configurator_opt_group` int(11) NOT NULL, `id_configurator_opt` int(11) NOT NULL, `price` decimal(20,6) NOT NULL, PRIMARY KEY (`id_product_configurator_opt_impact`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", "ALTER TABLE `"._DB_PREFIX_."cart_product` ADD `id_configurator` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `id_product_attribute`;", "ALTER TABLE `"._DB_PREFIX_."cart_product` DROP PRIMARY KEY, ADD PRIMARY KEY (`id_cart`, `id_product`, `id_product_attribute`, `id_address_delivery`, `id_configurator`) USING BTREE;", "ALTER TABLE `"._DB_PREFIX_."order_detail` ADD `id_configurator` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `product_price`;", ); if (count($sql) > 0) { foreach($sql as $s) { if (!Db::getInstance()->execute($s)) { return false; } } } // Menu if (!$this->installTab('AdminCatalog', 'AdminAntadisConfigurator', 'Configurator Options')) { return false; } // Install AdminAntadisConfiguratorProductGroup AdminAntadisConfiguratorProductImpact if (!$this->installTab('AdminCatalog', 'AdminAntadisConfiguratorProductGroup', 'Configurator Product Group', 0) || !$this->installTab('AdminCatalog', 'AdminAntadisConfiguratorProductImpact', 'Configurator Product Impact', 0)) { return false; } // Hook if (!$this->registerHook('Header') || !$this->registerHook('displayAdminProductsExtra') || !$this->registerHook('displayAdminOrderProductConfigurator') || !$this->registerHook('displayProductTabContent') || !$this->registerHook('displayProductForm') || !$this->registerHook('ModuleRoutes')) { return false; } // All went well! return true; } public function uninstall() { // Call uninstall parent method if (!parent::uninstall()) { return false; } // Menu if (!$this->uninstallTab('AdminAntadisConfigurator') || !$this->uninstallTab('AdminAntadisConfiguratorProduct')) { return false; } // Hook if (!$this->unregisterHook('Header') || !$this->unregisterHook('displayAdminProductsExtra') || !$this->unregisterHook('displayAdminOrderProductConfigurator') || !$this->unregisterHook('displayProductTabContent') || !$this->unregisterHook('displayProductForm') || !$this->unregisterHook('ModuleRoutes')) { return false; } // All went well! return true; } public function getContent() { $ajax_hook = Tools::getValue('ajax_hook'); if ($ajax_hook != '') { $ajax_method = 'hook'.ucfirst($ajax_hook); if (method_exists($this, $ajax_method)) { die($this->{$ajax_method}(array())); } } $controller = $this->getHookController('getContent'); return $controller->run(); } public function installTab($parent, $class_name, $name, $active = 1) { // Create new admin tab $tab = new Tab(); $tab->id_parent = (int)Tab::getIdFromClassName($parent); $tab->name = array(); foreach (Language::getLanguages(true) as $lang) { $tab->name[$lang['id_lang']] = $name; $tab->class_name = $class_name; $tab->module = $this->name; $tab->active = $active; return $tab->add(); } } public function uninstallTab($class_name) { // Retrieve Tab ID $id_tab = (int)Tab::getIdFromClassName($class_name); // Load tab $tab = new Tab((int)$id_tab); // Delete it return $tab->delete(); } public function getHookController($hook_name) { // Include the controller file require_once(dirname(__FILE__).'/controllers/hook/'. $hook_name.'.php'); // Build dynamically the controller name $controller_name = $this->name.$hook_name.'Controller'; // Instantiate controller $controller = new $controller_name($this, __FILE__, $this->_path); // Return the controller return $controller; } public function hookDisplayAdminProductsExtra($params) { $controller = $this->getHookController('displayAdminProductsExtra'); return $controller->run(); } public function hookDisplayProductTabContent($params) { $controller = $this->getHookController('displayProductTabContent'); return $controller->run(); } public function hookDisplayProductForm($params) { $controller = $this->getHookController('displayProductForm'); return $controller->run(); } public function hookDisplayAdminOrderProductConfigurator($params) { $controller = $this->getHookController('displayAdminOrderProductConfigurator'); return $controller->run($params); } public function hookModuleRoutes() { $controller = $this->getHookController('modulesRoutes'); return $controller->run(); } public function hookHeader($params) { // Diplay CSS and JS only on product page if ($this->context->controller instanceof ProductController) { // JQuery UI Date Picker $this->context->controller->addJqueryUI('ui.datepicker'); // JQuery File Upload $this->context->controller->addCSS($this->_path.'views/jQuery-File-Upload/css/jquery.fileupload.css'); $this->context->controller->addJS($this->_path.'views/jQuery-File-Upload/js/vendor/jquery.ui.widget.js'); $this->context->controller->addJS($this->_path.'views/jQuery-File-Upload/js/jquery.iframe-transport.js'); $this->context->controller->addJS($this->_path.'views/jQuery-File-Upload/js/jquery.fileupload.js'); // JS Configurator $this->context->controller->addJS($this->_path.'views/js/configurator.js'); } } }