_object = false;
$this->controller = 'AdminModules';
$this->module_name = 'ant_customgroup';
$this->config_tab = (bool)$config_tab;
if ($config_tab) {
$this->controller = 'AdminAntCustomgroup';
}
$this->helperForm = new HelperFormBootstrap();
$this->helperForm->_inputSwitch = true;
}
public function display()
{
parent::displayForm();
$this->_html = '';
$this->_postProcess();
$this->_addCss();
$this->_html .= $this->helperForm->renderStyle();
$this->_displayForm();
$this->_displayList();
$this->_html .='
';
$this->_addJs();
$this->_html .= $this->helperForm->renderScript();
echo $this->_html;
}
protected function _addJs()
{
$this->helperForm->_js .= '';
}
protected function _addCss()
{
$this->helperForm->_css .='
.table tr th {
background: #565485;
background: rgba(86,84,133,0.9);
color: #fff;
font-size: 12px;
}
.table tr:nth-child(even) {
background: #F1F1F1;
}
.table .input-group-btn .btn {
padding: 4px 5px;
color: #504d8b;
}
.table .input-group-btn .btn .anticon{
font-size: 12px;
}
.bg-grey{
background: #EFEFEF;
border-radius:4px;
}
.bg-grey .div-title {
border-bottom: 2px solid #504D8B;
}
';
}
protected function _displayList()
{
global $cookie, $currentIndex;
$id_lang = (int)$cookie->id_lang;
$custom_groups = CustomGroup::getGroups(false);
$_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']);
$row_data = array();
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$this->_html .='
'.$this->l('Liste des groupes').'
'.$this->l('ID').' |
'.$this->l('Name').' |
'.$this->l('Subscription days').' |
'.$this->l('Last order days').' |
'.$this->l('Retention days').' |
'.$this->l('Minimum order amount').' |
'.$this->l('Active').' |
'.$this->l('Nb').' |
'.$this->l('Action').' |
';
foreach ($custom_groups as $custom_group)
{
// $selected_order_stats = "";
// foreach (CustomGroup::getOrderStatsIds((int)$custom_group['id_custom_group']) as $order_stats_id)
// {
// $selected_order_stats .= Customer::$order_stats_categories[$order_stats_id] . ",";
// }
// $selected_sales = "";
// if(count(CustomGroup::getSalesIds((int)$custom_group['id_custom_group'])) > 0){
// foreach (
// Db::getInstance()->executeQ('
// SELECT cl.name
// FROM `' . _DB_PREFIX_ . 'privatesale` ps
// ON cl.id_category = ps.id_category
// AND cl.id_lang = ' . $id_lang . '
// WHERE ps.id_sale IN (' .
// implode( ',' , CustomGroup::getSalesIds((int)$custom_group['id_custom_group'])) .
// ")") as $row)
// {
// $selected_sales .= $row['name'] . ",";
// };
// }
$customer_number = CustomGroup::getCount((int)$custom_group['id_custom_group']);
if ($custom_group['minimum_order_amount'] > 0.0){
$minimum_order_amount = Tools::displayPrice($custom_group['minimum_order_amount'], $currency, false);
} else {
$minimum_order_amount = '';
}
if ($custom_group['register_date'] == 0) {
$register_date = '';
} else {
$register_date = $custom_group['register_date'] . " jours";
}
if ($custom_group['last_order_date'] == 0) {
$last_order_date = '';
} else {
$last_order_date = $custom_group['last_order_date'] . " jours";
}
if ($custom_group['nb_retention_days'] == 0) {
$nb_retention_days = '';
} else {
$nb_retention_days = $custom_group['nb_retention_days'] . " jours";
}
// $row_data[] = array(
// 'id_custom_group' => (int)$custom_group['id_custom_group'],
// 'name' => $custom_group['name'],
// 'register_date' => $register_date,
// 'last_order_date' => $last_order_date,
// 'nb_retention_days' => $nb_retention_days,
// 'minimum_order_amount' => $minimum_order_amount,
// // 'id_sales' => $selected_sales,
// // 'id_order_stats_categories' => $selected_order_stats,
// 'active' => (int)$custom_group['active'],
// 'number' => $customer_number
// );
$this->_html .='
#'.$custom_group['id_custom_group'].' |
'.$custom_group['name'].' |
'.$register_date.' |
'.$last_order_date.' |
'.$nb_retention_days.' |
'.$minimum_order_amount.' |
'.((int)$custom_group['active']?'':'').' |
'.$customer_number.' |
|
';
}
$this->_html .='
';
}
protected function _postProcess()
{
if (Tools::isSubmit('newGroup')) {
} elseif (Tools::isSubmit('addGroup')) {
$this->_addOrUpdateGroup(false);
} elseif (Tools::isSubmit('editGroup')) {
$this->_addOrUpdateGroup(true);
} elseif (Tools::isSubmit('loadGroup') && Tools::getValue('id')) {
$this->_object = new CustomGroup((int)Tools::getValue('id'));
} elseif (Tools::isSubmit('deleteGroup') && Tools::getValue('id')) {
$deleted_group = new CustomGroup((int)Tools::getValue('id'));
$res = $deleted_group->delete();
if ($res) {
$this->_html .= HelperFormBootstrap::displaySuccess($this->l('Group deleted : #') . (int)Tools::getValue('id'));
} else {
$this->_html .= HelperFormBootstrap::displayError($this->l('Group cannot be deleted : #') . (int)Tools::getValue('id'));
}
return $res;
} elseif (Tools::isSubmit('refreshGroup') && Tools::getValue('id')) {
if (CustomGroup::refreshCustomGroupStatic(Tools::getValue('id'))) {
$this->_html .= HelperFormBootstrap::displaySuccess($this->l('Group updated with : #') . CustomGroup::getCount(Tools::getValue('id')));
} else {
$this->_html .= HelperFormBootstrap::displayError($this->l('Error occured during update for group : #') . (int)Tools::getValue('id'));
}
}
}
protected function _addOrUpdateGroup($edit = false)
{
if ($edit) {
$customGroup = new CustomGroup((int)Tools::getValue('id_custom_group'));
} else {
$customGroup = new CustomGroup();
}
$id_order_stats_categories = array();
// foreach (Tools::getValue('id_order_stats_categories') as $id_order_stats_category) {
// $id_order_stats_categories[] = $id_order_stats_category;
// }
if (count($id_order_stats_categories) > 0) {
$customGroup->customer_order_stats = $id_order_stats_categories;
} else {
$customGroup->customer_order_stats = array();
}
$customGroup->name = Tools::getValue('name');
$customGroup->register_date = (int)Tools::getValue('register_date');
$customGroup->last_order_date = (int)Tools::getValue('last_order_date');
$customGroup->nb_retention_days = (int)Tools::getValue('nb_retention_days');
$customGroup->minimum_order_amount = (float)Tools::getValue('minimum_order_amount');
$customGroup->sales = array();
$customGroup->active = (int)Tools::getValue('active');
// if ($sales_id_string = trim(Tools::getValue('comma_separated_sales'))) {
// if (substr($sales_id_string, strlen($sales_id_string) - 1, 1) == ",") {
// $sales_id_string = substr($sales_id_string, 0, strlen($sales_id_string) - 1);
// }
// $customGroup->sales = explode(",", $sales_id_string);
// } else {
// $customGroup->sales = array();
// }
if ($customGroup->save()) {
if ($edit) {
$this->_html .= HelperFormBootstrap::displaySuccess($this->l('Group has been updated'));
} else {
$this->_html .= HelperFormBootstrap::displaySuccess($this->l('Group has been created'));
}
} else {
$this->_html .= HelperFormBootstrap::displayError($this->l('Error occured while updating group'));
}
}
private function _displayForm()
{
global $cookie, $currentIndex;
$order_stats_categories = array();
$selected_order_stats_array = array();
if (Validate::isLoadedObject($this->_object)){
$customGroup = $this->_object;
}
// if (Validate::isLoadedObject($this->_object)) {
// $selected_order_stats_array = CustomGroup::getOrderStatsIds((int)$this->_object->id);
// $this->_object->comma_separated_sales = implode(",", CustomGroup::getSalesIds($this->_object->id));
// }
// foreach (Customer::$order_stats_categories as $key => $value) {
// if (!(is_null($value))) {
// $selected = (bool)($this->_object && in_array($key, $selected_order_stats_array, true));
// $order_stats_categories[] = array(
// 'label' => (int)$key . ' - ' . $value,
// 'value' => (int)$key,
// 'selected' => $selected
// );
// }
// }
$this->helperForm->_forms = array(
array(
'action' => $currentIndex . '&token=' . Tools::getAdminTokenLite('AdminAntCustomgroup'),
'title' => ' '.$this->l('Segmentation'),
'class' => 'form-horizontal',
'class_div' => 'col-md-12',
'sections' => array(
array(
'class' => 'col-md-6',
'inputs' => array(
array(
'type' => 'simpleText',
'name' => 'name',
'label-class' => 'col-md-5',
'input-class' => 'col-md-6',
'label' => $this->l('Name'),
'default' => (isset($customGroup)?$customGroup->name:'')
),
array(
'type' => 'simpleText',
'name' => 'register_date',
'label-class' => 'col-md-5',
'input-class' => 'col-md-6',
'label' => $this->l('Registration Date'),
'default' => (isset($customGroup)?$customGroup->register_date:'')
),
array(
'type' => 'simpleText',
'name' => 'last_order_date',
'label-class' => 'col-md-5',
'input-class' => 'col-md-6',
'label' => $this->l('Last order date'),
'default' => (isset($customGroup)?$customGroup->last_order_date:'')
),
array(
'type' => 'simpleText',
'name' => 'nb_retention_days',
'label-class' => 'col-md-5',
'input-class' => 'col-md-6',
'label' => $this->l('Number of days'),
'default' => (isset($customGroup)?$customGroup->nb_retention_days:'')
),
array(
'type' => 'simpleText',
'name' => 'minimum_order_amount',
'label-class' => 'col-md-5',
'input-class' => 'col-md-6',
'label' => $this->l('Minimum order amount'),
'default' => (isset($customGroup)?$customGroup->minimum_order_amount:'')
),
array(
'type' => 'switch',
'label' => $this->l('Active'),
'label-class' => 'col-md-5',
'input-class' => 'col-md-6',
'class-group' => 'switch',
'name' => 'active',
'title' => ' ',
'default' => (isset($customGroup)?($customGroup->active==0?0:1):1),
'checked' => (isset($customGroup)?($customGroup->active==0?0:1):1),
),
),
'actions' => array(),
'actions-class' => 'text-right',
),
array(
'class' => 'col-md-6 bg-grey',
'title' => ' Informations',
'info_html' => '
L\'inscrit est ajouté au groupe une fois la condition requise et en ressort lorsqu\'il depasse cette date
Le nombre de jours depuis l’inscription OU depuis la dernière commande est strictement égal à la valeur renseignée
si un nombre de jours de rétention est spécifié (Nombre de jours de rétention différent de 0).
Par exemple :
- Nb jrs depuis l\'inscription : 8
- Nombre de jours de rétention : 31
Tous les membres inscrits il y a 8 jours exactement resteront dans le groupe pendant 31 jours (et pourront utiliser le code reçu pendant 31 jours).
A l’inverse, s’il n’y a pas de nombre de jours de rétention précisé, alors pour le nombre de jours depuis l’inscription ou la dernière commande, la valeur renseignée s’entend supérieure ou égale.
- Nb jrs depuis l\'inscription : 8
- Nombre de jours de rétention : 0
Tous les membres inscrits depuis 8 jours et plus peuvent utiliser le code.
'
),
),
'actions' => array(),
'actions-class' => 'text-right',
)
);
if (isset($customGroup)) {
$this->helperForm->_forms[0]['sections'][0]['title'] = "Editer le groupe ".$customGroup->name;
$this->helperForm->_forms[0]['sections'][0]['inputs'][] = array(
'type' => 'hidden',
'name' => 'id_custom_group',
'value' => $customGroup->id,
'class' => 'large'
);
$this->helperForm->_forms[0]['sections'][0]['actions'] = array(
array(
'type' => 'submit',
'class' => 'btn-default',
'name' => 'newGroup',
'value' => $this->l('Nouveau groupe')
),
array(
'type' => 'submit',
'class' => 'btn-primary',
'name' => 'editGroup',
'value' => $this->l('Editer le groupe')
),
);
} else {
$this->helperForm->_forms[0]['sections'][0]['title'] = "Ajouter un groupe";
$this->helperForm->_forms[0]['sections'][0]['actions'] = array(
array(
'type' => 'submit',
'class' => 'btn-primary',
'name' => 'addGroup',
'value' => $this->l('Ajouter le groupe')
),
);
}
$this->helperForm->renderForm();
}
}