117 lines
4.0 KiB
PHP
117 lines
4.0 KiB
PHP
<?php
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
class Ant_Customgroup extends Module
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
$this->name = 'ant_customgroup';
|
|
$this->tab = 'administration';
|
|
$this->author = 'Antadis';
|
|
$this->version = '1.0';
|
|
$this->need_instance = 0;
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Conditionnal Customer groups');
|
|
$this->description = $this->l('Allows the creation of specificustomer groups for discount limitations.');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (!$this->installDB()){
|
|
return false;
|
|
}
|
|
|
|
if(!(parent::install())) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function uninstall() {
|
|
|
|
if(parent::uninstall() == false) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private function installDB()
|
|
{
|
|
$result = true;
|
|
# Add tables
|
|
$query = '
|
|
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'custom_group` (
|
|
`id_custom_group` INTEGER NOT NULL AUTO_INCREMENT,
|
|
`name` VARCHAR(128) NOT NULL,
|
|
`register_date` INTEGER NOT NULL DEFAULT 0,
|
|
`last_order_date` INTEGER NOT NULL DEFAULT 0,
|
|
`nb_retention_days` INTEGER NOT NULL,
|
|
`minimum_order_amount` DECIMAL(20, 6) DEFAULT 0.0 NOT NULL,
|
|
`active` BOOL NOT NULL DEFAULT 1,
|
|
`date_add` DATETIME NOT NULL,
|
|
`date_upd` DATETIME NOT NULL,
|
|
PRIMARY KEY(`id_custom_group`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8
|
|
';
|
|
|
|
$result = Db::getInstance()->Execute($query);
|
|
|
|
$query = '
|
|
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'custom_group_customer` (
|
|
`id_custom_group` INTEGER NOT NULL,
|
|
`id_customer` INTEGER NOT NULL,
|
|
CONSTRAINT `PRIMARY` PRIMARY KEY (id_customer, id_custom_group),
|
|
KEY `custom_group_customer_cg_index` (id_custom_group),
|
|
KEY `custom_group_customer_c_index` (id_customer)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8
|
|
';
|
|
|
|
$result = (Db::getInstance()->Execute($query) and $result);
|
|
|
|
// $query = '
|
|
// CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'custom_group_order_stats` (
|
|
// `id_custom_group` INTEGER NOT NULL,
|
|
// `id_order_stats` INTEGER NOT NULL,
|
|
// PRIMARY KEY (id_custom_group, id_order_stats),
|
|
// KEY `custom_group_order_stats_cg_index` (id_custom_group),
|
|
// KEY `custom_group_order_stats_os_index` (id_order_stats)
|
|
// ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8
|
|
// ';
|
|
|
|
// $result = (Db::getInstance()->Execute($query) and $result);
|
|
|
|
// $query = '
|
|
// CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'custom_group_sales` (
|
|
// `id_custom_group` INTEGER NOT NULL,
|
|
// `id_sale` INTEGER NOT NULL,
|
|
// PRIMARY KEY (id_custom_group, id_sale),
|
|
// KEY `custom_group_sales_cg_index` (id_custom_group),
|
|
// KEY `custom_group_sales_s_index` (id_sale)
|
|
// ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8
|
|
// ';
|
|
|
|
// $result = (Db::getInstance()->Execute($query) and $result);
|
|
|
|
$query = '
|
|
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'custom_group_discount` (
|
|
`id_custom_group` INTEGER NOT NULL,
|
|
`id_discount` INTEGER NOT NULL,
|
|
PRIMARY KEY (id_custom_group, id_discount),
|
|
KEY `custom_group_discount_cg_index` (id_custom_group),
|
|
KEY `custom_group_discount_d_index` (id_discount)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8
|
|
';
|
|
|
|
$result = (Db::getInstance()->Execute($query) and $result);
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
}
|