97 lines
2.5 KiB
PHP
97 lines
2.5 KiB
PHP
<?php
|
|
if (!defined('_CAN_LOAD_FILES_'))
|
|
exit;
|
|
|
|
include_once _PS_MODULE_DIR_.'antadis_productpack/controllers/admin/AdminProductPack.php';
|
|
|
|
class Antadis_ProductPack extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'antadis_productpack';
|
|
$this->tab = 'administration';
|
|
$this->version = '1.0';
|
|
$this->author = 'Antadis';
|
|
$this->need_instance = 0;
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Antadis products pack');
|
|
$this->description = $this->l('Gestion de packs produits');
|
|
$this->secure_key = Tools::encrypt($this->name);
|
|
|
|
$this->confirmUninstall = $this->l('Are you sure ?');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (Shop::isFeatureActive()) {
|
|
Shop::setContext(Shop::CONTEXT_ALL);
|
|
}
|
|
|
|
if (!parent::install()) {
|
|
return false;
|
|
}
|
|
|
|
$new_tab = new Tab();
|
|
$new_tab->class_name = 'AdminProductPack';
|
|
$new_tab->id_parent = Tab::getIdFromClassName('AdminCatalog');
|
|
$new_tab->module = $this->name;
|
|
$languages = Language::getLanguages();
|
|
foreach ($languages as $language) {
|
|
$new_tab->name[$language['id_lang']] = $this->l('Packs produits');
|
|
}
|
|
$result = $new_tab->add();
|
|
|
|
$sql = 'CREATE TABLE `'._DB_PREFIX_.'productpack` (
|
|
`id_productpack` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`id_product_root` INTEGER UNSIGNED NOT NULL,
|
|
PRIMARY KEY (`id_productpack`)
|
|
)';
|
|
$result = Db::getInstance()->execute($sql);
|
|
if (!$result) {
|
|
$this->uninstallTab();
|
|
}
|
|
|
|
$sql = 'CREATE TABLE `'._DB_PREFIX_.'productpack_association` (
|
|
`id_productpack` INTEGER UNSIGNED NOT NULL,
|
|
`id_product_associated` INTEGER UNSIGNED NOT NULL,
|
|
INDEX `index_productpack_association` (`id_productpack`, `id_product_associated`)
|
|
)';
|
|
$result = Db::getInstance()->execute($sql);
|
|
if (!$result) {
|
|
$this->uninstallTab();
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
$sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'productpack_association`';
|
|
Db::getInstance()->execute($sql);
|
|
|
|
$sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'productpack`';
|
|
Db::getInstance()->execute($sql);
|
|
|
|
$this->uninstallTab();
|
|
|
|
return parent::uninstall();
|
|
}
|
|
|
|
private function uninstallTab()
|
|
{
|
|
$idTab = Tab::getIdFromClassName('AdminProductPack');
|
|
if ($idTab) {
|
|
$tab = new Tab($idTab);
|
|
$tab->delete();
|
|
}
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
}
|