183 lines
4.6 KiB
PHP
Executable File
183 lines
4.6 KiB
PHP
Executable File
<?php
|
|
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
|
|
|
class PrivateSales_Delay extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'privatesales_delay';
|
|
$this->tab = 'pricing_promotion';
|
|
$this->author = 'Antadis';
|
|
$this->version = '1.0';
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Private Sales Delays');
|
|
$this->description = $this->l('Adds delays to private sales');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if(!Module::isInstalled('privatesales')
|
|
&& $this->registerHook('deliveryDelay')) {
|
|
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.',
|
|
"AdminPrivateSalesDelay",
|
|
"privatesales_delay",
|
|
'.$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élais',
|
|
'en' => 'Delays',
|
|
);
|
|
$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'].'")
|
|
');
|
|
}
|
|
}
|
|
|
|
# Add delays tables
|
|
$query = '
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_delay` (
|
|
`id_delay` INTEGER NOT NULL AUTO_INCREMENT,
|
|
PRIMARY KEY(`id_delay`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
|
';
|
|
if(!Db::getInstance()->Execute($query)) {
|
|
return FALSE;
|
|
}
|
|
$query = '
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_delay_lang` (
|
|
`id_delay` INTEGER NOT NULL,
|
|
`id_lang` INTEGER NOT NULL,
|
|
`name` VARCHAR(255),
|
|
`short_name` VARCHAR(64),
|
|
`value` tinyint unsigned not null,
|
|
PRIMARY KEY(`id_delay`, `id_lang`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
|
';
|
|
if(!Db::getInstance()->Execute($query)) {
|
|
return FALSE;
|
|
}
|
|
|
|
# Register hooks
|
|
if(!parent::install()) {
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
function uninstall()
|
|
{
|
|
$tab = Db::getInstance()->Execute('
|
|
SELECT `id_tab`
|
|
FROM `'._DB_PREFIX_.'tab`
|
|
WHERE `module` = "privatesales_delay"
|
|
');
|
|
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_delay"
|
|
');
|
|
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('DROP TABLE `'._DB_PREFIX_.'privatesale_delay`');
|
|
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'privatesale_delay_lang`');
|
|
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'privatesale_module` WHERE `modulename` = "privatesales_delay"');
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
public function hookdeliveryDelay($params)
|
|
{
|
|
global $smarty, $cookie;
|
|
|
|
$id_order = $params['id_order'];
|
|
$order = new Order((int)$id_order);
|
|
|
|
if(!Validate::isLoadedObject($order)) { return false; }
|
|
|
|
if (!class_exists('SaleDelay')) {
|
|
require_once _PS_ROOT_DIR_.'/modules/privatesales_delay/saledelay.php';
|
|
}
|
|
|
|
if ($order->valid) {
|
|
$products = $order->getProducts();
|
|
$products = SaleDelay::associateDelay($products);
|
|
$delays = array_keys($products);
|
|
if ($order!=null) {
|
|
$date = new DateTime($order->date_add);
|
|
} else {
|
|
$date = new DateTime();
|
|
}
|
|
$delivery_date = SaleDelay::getDeliveryDate($delays, $cookie->id_lang, $date, true);
|
|
|
|
$smarty->assign(array(
|
|
'delivery_date' => $delivery_date
|
|
));
|
|
|
|
return $this->display(__FILE__, 'delivery_date.tpl');
|
|
}
|
|
}
|
|
|
|
}
|
|
|