147 lines
3.9 KiB
PHP
147 lines
3.9 KiB
PHP
|
<?php
|
||
|
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
||
|
|
||
|
class PrivateSales_Countdown extends Module {
|
||
|
public function __construct() {
|
||
|
$this->name = 'privatesales_countdown';
|
||
|
$this->tab = 'pricing_promotion';
|
||
|
$this->author = 'Antadis';
|
||
|
$this->version = '1.0';
|
||
|
parent::__construct();
|
||
|
|
||
|
$this->displayName = $this->l('Private Sales Countdown');
|
||
|
$this->description = $this->l('Adds a countdown for private sales');
|
||
|
}
|
||
|
|
||
|
public function install() {
|
||
|
if(!Module::isInstalled('privatesales')) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
# Install admin tab
|
||
|
$id_mod = Db::getInstance()->ExecuteS('
|
||
|
SELECT `id_tab`
|
||
|
FROM `'._DB_PREFIX_.'tab`
|
||
|
WHERE `class_name` = "AdminPrivateSales"
|
||
|
');
|
||
|
if(count($id_mod) == 0) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
$id_mod = $id_mod[0]['id_tab'];
|
||
|
$posmax = Db::getInstance()->ExecuteS('SELECT MAX(`position`) + 1 AS `max` FROM `'._DB_PREFIX_.'tab` WHERE `id_parent` = '.$id_mod);
|
||
|
$posmax = $posmax[0]['max'];
|
||
|
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'tab`
|
||
|
VALUES (
|
||
|
DEFAULT,
|
||
|
'.$id_mod.',
|
||
|
"AdminPrivateSalesCountdown",
|
||
|
"privatesales_countdown",
|
||
|
'.$posmax.'
|
||
|
)
|
||
|
');
|
||
|
$tab_id = Db::getInstance()->Insert_ID();
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'access`
|
||
|
VALUES (1, '.$tab_id.', 1, 1, 1, 1)
|
||
|
');
|
||
|
|
||
|
$tabs_i18n = array(
|
||
|
'fr' => 'Décompte',
|
||
|
'en' => 'Countdown',
|
||
|
);
|
||
|
$langs = Db::getInstance()->ExecuteS('
|
||
|
SELECT `id_lang`, `iso_code`
|
||
|
FROM `'._DB_PREFIX_.'lang`
|
||
|
');
|
||
|
foreach($langs as $lang) {
|
||
|
if(isset($tabs_i18n[$lang['iso_code']])) {
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'tab_lang`
|
||
|
VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n[$lang['iso_code']].'")
|
||
|
');
|
||
|
} else {
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'tab_lang`
|
||
|
VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n['en'].'")
|
||
|
');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Register hooks
|
||
|
if(!parent::install()
|
||
|
OR !$this->registerHook('privatesales_product')
|
||
|
OR !$this->registerHook('privatesales_category')) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'privatesale_module`
|
||
|
VALUES (
|
||
|
(SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = "privatesales_countdown"),
|
||
|
"privatesales_countdown"
|
||
|
)
|
||
|
');
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
function uninstall() {
|
||
|
$tab = Db::getInstance()->Execute('
|
||
|
SELECT `id_tab`
|
||
|
FROM `'._DB_PREFIX_.'tab`
|
||
|
WHERE `module` = "privatesales_countdown"
|
||
|
');
|
||
|
if(count($tab) == 0) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
$tab = $tab[0];
|
||
|
|
||
|
Db::getInstance()->Execute('
|
||
|
DELETE FROM `'._DB_PREFIX_.'tab_lang`
|
||
|
WHERE `id_tab` = '.$tab['id_tab']
|
||
|
);
|
||
|
Db::getInstance()->Execute('
|
||
|
DELETE FROM `'._DB_PREFIX_.'access`
|
||
|
WHERE `id_tab` = '.$tab['id_tab']
|
||
|
);
|
||
|
Db::getInstance()->Execute('
|
||
|
DELETE FROM `'._DB_PREFIX_.'tab`
|
||
|
WHERE `module` = "privatesales_countdown"
|
||
|
');
|
||
|
Db::getInstance()->Execute('
|
||
|
UPDATE `'._DB_PREFIX_.'tab`
|
||
|
SET `position` = `position` - 1
|
||
|
WHERE `id_parent` = '.$tab['id_parent'].' AND `position` > '.$tab['position']
|
||
|
);
|
||
|
|
||
|
if(parent::uninstall() == FALSE) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'privatesale_module` WHERE `modulename` = "privatesales_countdown"');
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
public function hookPrivateSales_Product($params) {
|
||
|
global $smarty;
|
||
|
$product = new Product(Tools::getValue('id_product'));
|
||
|
$smarty->assign(array(
|
||
|
'sale' => Sale::getSaleFromCategory($product->id_category_default),
|
||
|
'countdown_format' => Configuration::get('PRIVATESALES_COUNTDOWNFMT')
|
||
|
));
|
||
|
return $this->display(__FILE__, 'product.tpl');
|
||
|
}
|
||
|
|
||
|
public function hookPrivateSales_Category($params) {
|
||
|
global $smarty;
|
||
|
$smarty->assign(array(
|
||
|
'sale' => Sale::getSaleFromCategory(Tools::getValue('id_category')),
|
||
|
'countdown_format' => Configuration::get('PRIVATESALES_COUNTDOWNFMT')
|
||
|
));
|
||
|
return $this->display(__FILE__, 'category.tpl');
|
||
|
}
|
||
|
}
|