267 lines
10 KiB
PHP
Raw Normal View History

<?php
if (!defined('_PS_VERSION_')) {
exit;
}
require_once dirname(__FILE__).'/classes/ConfiguratorOptGroup.php';
require_once dirname(__FILE__).'/classes/ConfiguratorOpt.php';
require_once dirname(__FILE__).'/classes/ProductConfiguratorOptGroup.php';
require_once dirname(__FILE__).'/classes/ProductConfiguratorOptImpact.php';
2017-06-09 11:10:25 +02:00
require_once dirname(__FILE__).'/classes/ConfiguratorStorage.php';
class AntadisConfigurator extends Module
{
public function __construct()
{
$this->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;
}
2017-06-15 12:52:59 +02:00
//Database
$sql = array(
"CREATE TABLE IF NOT EXISTS `ps_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 IF NOT EXISTS `ps_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 `ps_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 `ps_configurator_opt_lang` (
`id_configurator_opt` int(11) NOT NULL,
`id_lang` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id_configurator_opt`,`id_lang`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;",
"CREATE TABLE IF NOT EXISTS `ps_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 IF NOT EXISTS `ps_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,
`position` tinyint(1) NOT NULL,
PRIMARY KEY (`id_product_configurator_opt_group`),
UNIQUE KEY `id_product` (`id_product`,`id_configurator_opt_group`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;",
"CREATE TABLE IF NOT EXISTS `ps_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;",
2017-06-27 12:21:47 +02:00
/*"ALTER TABLE `ps_cart_product` ADD `id_configurator` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `id_product_attribute`;",
"ALTER TABLE `ps_cart_product` DROP PRIMARY KEY, ADD PRIMARY KEY (`id_cart`, `id_product`, `id_product_attribute`, `id_address_delivery`, `id_configurator`) USING BTREE;",
2017-06-27 12:21:47 +02:00
"ALTER TABLE `ps_order_detail` ADD `id_configurator` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `product_price`;",*/
2017-06-15 12:52:59 +02:00
);
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;
}
2017-06-14 15:14:07 +02:00
// Install AdminAntadisConfiguratorProductGroup AdminAntadisConfiguratorProductImpact
if (!$this->installTab('AdminCatalog', 'AdminAntadisConfiguratorProductGroup', 'Configurator Product Group', 0) ||
!$this->installTab('AdminCatalog', 'AdminAntadisConfiguratorProductImpact', 'Configurator Product Impact', 0)) {
return false;
}
// Hook
2017-06-27 11:47:36 +02:00
if (!$this->registerHook('Header') ||
!$this->registerHook('displayAdminProductsExtra') ||
2017-06-09 14:35:12 +02:00
!$this->registerHook('displayAdminOrderProductConfigurator') ||
!$this->registerHook('displayProductTabContent') ||
2017-06-23 17:07:55 +02:00
!$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
2017-06-27 12:21:47 +02:00
if (!$this->unregisterHook('Header') ||
!$this->unregisterHook('displayAdminProductsExtra') ||
2017-06-09 14:35:12 +02:00
!$this->unregisterHook('displayAdminOrderProductConfigurator') ||
!$this->unregisterHook('displayProductTabContent') ||
2017-06-23 17:07:55 +02:00
!$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();
}
2017-06-14 18:21:53 +02:00
public function hookDisplayProductForm($params)
{
$controller = $this->getHookController('displayProductForm');
return $controller->run();
}
2017-06-09 14:35:12 +02:00
public function hookDisplayAdminOrderProductConfigurator($params)
{
$controller = $this->getHookController('displayAdminOrderProductConfigurator');
return $controller->run($params);
}
2017-06-23 17:07:55 +02:00
public function hookModuleRoutes()
{
$controller = $this->getHookController('modulesRoutes');
return $controller->run();
}
2017-06-27 12:21:47 +02:00
public function hookHeader($params)
{
// Diplay CSS and JS only on product page
if ($this->context->controller instanceof ProductController) {
2017-06-27 12:21:47 +02:00
// JQuery UI Date Picker
$this->context->controller->addJqueryUI('ui.datepicker');
2017-06-27 11:47:36 +02:00
// 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');
2017-06-27 11:47:36 +02:00
// JS Configurator
2017-06-27 12:21:47 +02:00
$this->context->controller->addJS($this->_path.'views/js/configurator.js');
}
}
}