add module custom group
This commit is contained in:
parent
655b0e4236
commit
adf8bc8185
@ -126,15 +126,24 @@ class HelperFormBootstrap{
|
|||||||
|
|
||||||
foreach ($form['sections'] as $section) {
|
foreach ($form['sections'] as $section) {
|
||||||
|
|
||||||
$id = (isset($section['id']) && $section['id']) ? $section['id'] : false;
|
$id = (isset($section['id']) && $section['id']) ? $section['id'] : false;
|
||||||
$icon = (isset($section['icon']) && $section['icon']) ? $section['icon'] : false;
|
$icon = (isset($section['icon']) && $section['icon']) ? $section['icon'] : false;
|
||||||
$css = (isset($section['css']) && $section['css']) ? $section['css'] : false;
|
$css = (isset($section['css']) && $section['css']) ? $section['css'] : false;
|
||||||
$class = (isset($section['class']) && $section['class']) ? $section['class'] : false;
|
$class = (isset($section['class']) && $section['class']) ? $section['class'] : false;
|
||||||
$title = (isset($section['title']) && $section['title']) ? $section['title'] : '';
|
$title = (isset($section['title']) && $section['title']) ? $section['title'] : '';
|
||||||
|
$info = (isset($section['info']) && $section['info']) ? $section['info'] : '';
|
||||||
|
$info_html = (isset($section['info_html']) && $section['info_html']) ? $section['info_html'] : '';
|
||||||
|
|
||||||
// OPEN section
|
// OPEN section
|
||||||
$this->openSection($title, $id, $icon, $class, $css);
|
$this->openSection($title, $id, $icon, $class, $css);
|
||||||
|
|
||||||
|
if(!empty($info)){
|
||||||
|
$this->_html .= '<p>'.$info.'</p>';
|
||||||
|
}
|
||||||
|
if(!empty($info_html)){
|
||||||
|
$this->_html .= $info_html;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($section['inputs'] as $input) {
|
foreach ($section['inputs'] as $input) {
|
||||||
$this->addInput($input);
|
$this->addInput($input);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* 2007-2011 PrestaShop
|
* 2007-2011 PrestaShop
|
||||||
*
|
*
|
||||||
* NOTICE OF LICENSE
|
* NOTICE OF LICENSE
|
||||||
*
|
*
|
||||||
@ -30,25 +30,25 @@ class AdminDiscounts extends AdminTab
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
global $cookie;
|
global $cookie;
|
||||||
|
|
||||||
$this->table = 'discount';
|
$this->table = 'discount';
|
||||||
$this->className = 'Discount';
|
$this->className = 'Discount';
|
||||||
$this->lang = true;
|
$this->lang = true;
|
||||||
$this->edit = true;
|
$this->edit = true;
|
||||||
$this->delete = true;
|
$this->delete = true;
|
||||||
$this->_select = 'dtl.`name` AS discount_type,
|
$this->_select = 'dtl.`name` AS discount_type,
|
||||||
IF(a.id_discount_type = 1, CONCAT(a.value, " %"),
|
IF(a.id_discount_type = 1, CONCAT(a.value, " %"),
|
||||||
IF(a.id_discount_type = 2, CONCAT(a.value, " ", c.sign),
|
IF(a.id_discount_type = 2, CONCAT(a.value, " ", c.sign),
|
||||||
"--")) as strvalue';
|
"--")) as strvalue';
|
||||||
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'currency` c ON (c.`id_currency` = a.`id_currency`)
|
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'currency` c ON (c.`id_currency` = a.`id_currency`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'discount_type` dt ON (dt.`id_discount_type` = a.`id_discount_type`)
|
LEFT JOIN `'._DB_PREFIX_.'discount_type` dt ON (dt.`id_discount_type` = a.`id_discount_type`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'discount_type_lang` dtl ON (dt.`id_discount_type` = dtl.`id_discount_type` AND dtl.`id_lang` = '.(int)($cookie->id_lang).')';
|
LEFT JOIN `'._DB_PREFIX_.'discount_type_lang` dtl ON (dt.`id_discount_type` = dtl.`id_discount_type` AND dtl.`id_lang` = '.(int)($cookie->id_lang).')';
|
||||||
|
|
||||||
$typesArray = array();
|
$typesArray = array();
|
||||||
$types = Discount::getDiscountTypes((int)($cookie->id_lang));
|
$types = Discount::getDiscountTypes((int)($cookie->id_lang));
|
||||||
foreach ($types AS $type)
|
foreach ($types AS $type)
|
||||||
$typesArray[$type['id_discount_type']] = $type['name'];
|
$typesArray[$type['id_discount_type']] = $type['name'];
|
||||||
|
|
||||||
$this->fieldsDisplay = array(
|
$this->fieldsDisplay = array(
|
||||||
'id_discount' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
'id_discount' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||||
'name' => array('title' => $this->l('Code'), 'width' => 85, 'prefix' => '<span class="discount_name">', 'suffix' => '</span>', 'filter_key' => 'a!name'),
|
'name' => array('title' => $this->l('Code'), 'width' => 85, 'prefix' => '<span class="discount_name">', 'suffix' => '</span>', 'filter_key' => 'a!name'),
|
||||||
@ -58,18 +58,23 @@ class AdminDiscounts extends AdminTab
|
|||||||
'quantity' => array('title' => $this->l('Qty'), 'width' => 40, 'align' => 'right'),
|
'quantity' => array('title' => $this->l('Qty'), 'width' => 40, 'align' => 'right'),
|
||||||
'date_to' => array('title' => $this->l('To'), 'width' => 60, 'type' => 'date', 'align' => 'right'),
|
'date_to' => array('title' => $this->l('To'), 'width' => 60, 'type' => 'date', 'align' => 'right'),
|
||||||
'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
|
'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
|
||||||
|
|
||||||
$this->optionTitle = $this->l('Discounts options');
|
$this->optionTitle = $this->l('Discounts options');
|
||||||
$this->_fieldsOptions = array(
|
$this->_fieldsOptions = array(
|
||||||
'PS_VOUCHERS' => array('title' => $this->l('Enable vouchers:'), 'desc' => $this->l('Allow the use of vouchers in shop'), 'cast' => 'intval', 'type' => 'bool'),
|
'PS_VOUCHERS' => array('title' => $this->l('Enable vouchers:'), 'desc' => $this->l('Allow the use of vouchers in shop'), 'cast' => 'intval', 'type' => 'bool'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!class_exists('CustomGroup')) {
|
||||||
|
require_once(_PS_MODULE_DIR_.'ant_customgroup/models/CustomGroup.php');
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function copyFromPost(&$object, $table)
|
protected function copyFromPost(&$object, $table)
|
||||||
{
|
{
|
||||||
parent::copyFromPost($object, $table);
|
parent::copyFromPost($object, $table);
|
||||||
|
|
||||||
$object->cumulable = (!isset($_POST['cumulable']) ? false : true);
|
$object->cumulable = (!isset($_POST['cumulable']) ? false : true);
|
||||||
$object->cumulable_reduction = (!isset($_POST['cumulable_reduction']) ? false : true);
|
$object->cumulable_reduction = (!isset($_POST['cumulable_reduction']) ? false : true);
|
||||||
}
|
}
|
||||||
@ -87,7 +92,7 @@ class AdminDiscounts extends AdminTab
|
|||||||
if (Tools::getValue('id_discount_type') == 0)
|
if (Tools::getValue('id_discount_type') == 0)
|
||||||
$this->_errors[] = Tools::displayError('Please set a type for this voucher.');
|
$this->_errors[] = Tools::displayError('Please set a type for this voucher.');
|
||||||
if (Tools::getValue('id_discount_type') == 2 AND Tools::getValue('id_currency') == 0)
|
if (Tools::getValue('id_discount_type') == 2 AND Tools::getValue('id_currency') == 0)
|
||||||
$this->_errors[] = Tools::displayError('Please set a currency for this voucher.');
|
$this->_errors[] = Tools::displayError('Please set a currency for this voucher.');
|
||||||
if ((Tools::getValue('id_discount_type') == 1 || Tools::getValue('id_discount_type') == 2) && !Tools::getValue('value'))
|
if ((Tools::getValue('id_discount_type') == 1 || Tools::getValue('id_discount_type') == 2) && !Tools::getValue('value'))
|
||||||
$this->_errors[] = Tools::displayError('Please set a amount for this voucher.');
|
$this->_errors[] = Tools::displayError('Please set a amount for this voucher.');
|
||||||
if (!Validate::isBool_Id(Tools::getValue('id_target')))
|
if (!Validate::isBool_Id(Tools::getValue('id_target')))
|
||||||
@ -128,6 +133,15 @@ class AdminDiscounts extends AdminTab
|
|||||||
$this->_errors[] = Tools::displayError('Please set a category for this voucher.');
|
$this->_errors[] = Tools::displayError('Please set a category for this voucher.');
|
||||||
$this->copyFromPost($object, $this->table);
|
$this->copyFromPost($object, $this->table);
|
||||||
$result = $object->update(true, false, $categories);
|
$result = $object->update(true, false, $categories);
|
||||||
|
|
||||||
|
// @Override Antadis - link discount to custom group
|
||||||
|
if ($discount_custom_group_id = Tools::getValue("discount_custom_group")) {
|
||||||
|
CustomGroup::linkToDiscount($discount_custom_group_id, $object->id);
|
||||||
|
} else {
|
||||||
|
CustomGroup::linkToDiscount(null, $object->id);
|
||||||
|
}
|
||||||
|
// @End Antadis
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!$result)
|
if (!$result)
|
||||||
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b>';
|
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b>';
|
||||||
@ -155,10 +169,18 @@ class AdminDiscounts extends AdminTab
|
|||||||
$object = new $this->className();
|
$object = new $this->className();
|
||||||
$this->copyFromPost($object, $this->table);
|
$this->copyFromPost($object, $this->table);
|
||||||
$categories = Tools::getValue('categoryBox', null);
|
$categories = Tools::getValue('categoryBox', null);
|
||||||
if (!$object->add(true, false, $categories))
|
if (!$object->add(true, false, $categories)) {
|
||||||
$this->_errors[] = Tools::displayError('An error occurred while creating object.').' <b>'.$this->table.'</b>';
|
$this->_errors[] = Tools::displayError('An error occurred while creating object.').' <b>'.$this->table.'</b>';
|
||||||
elseif (($_POST[$this->identifier] = $object->id /* voluntary */) AND $this->postImage($object->id) AND $this->_redirect)
|
} elseif (($_POST[$this->identifier] = $object->id /* voluntary */) AND $this->postImage($object->id) AND $this->_redirect) {
|
||||||
|
|
||||||
|
// @Override Antadis
|
||||||
|
if ($discount_custom_group_id = Tools::getValue("discount_custom_group")) {
|
||||||
|
CustomGroup::linkToDiscount($discount_custom_group_id, $object->id);
|
||||||
|
}
|
||||||
|
// @End Override
|
||||||
|
|
||||||
Tools::redirectAdmin($currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&token='.$token);
|
Tools::redirectAdmin($currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&token='.$token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
||||||
@ -174,10 +196,19 @@ class AdminDiscounts extends AdminTab
|
|||||||
{
|
{
|
||||||
global $currentIndex, $cookie;
|
global $currentIndex, $cookie;
|
||||||
parent::displayForm();
|
parent::displayForm();
|
||||||
|
|
||||||
if (!($obj = $this->loadObject(true)))
|
if (!($obj = $this->loadObject(true)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// @Override Antadis - add custom group
|
||||||
|
$obj->custom_group_select = '<option value="">---</option>';
|
||||||
|
foreach (CustomGroup::getGroups(true) as $custom_group) {
|
||||||
|
$obj->custom_group_select .= '<option value="'.$custom_group['id_custom_group'].
|
||||||
|
(CustomGroup::isLinkedToDiscount($custom_group['id_custom_group'], $obj->id)?'" selected="selected" ':'" ').'>'.$custom_group['name'].'</option>';
|
||||||
|
}
|
||||||
|
// @End Override
|
||||||
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function discountType()
|
function discountType()
|
||||||
@ -196,13 +227,13 @@ class AdminDiscounts extends AdminTab
|
|||||||
$("#percent-span").css("display", "none");
|
$("#percent-span").css("display", "none");
|
||||||
$("#id_currency").css("display", "block");
|
$("#id_currency").css("display", "block");
|
||||||
$(\'#behavior_not_exhausted\').show();
|
$(\'#behavior_not_exhausted\').show();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ($("#id_discount_type").val() == 3)
|
else if ($("#id_discount_type").val() == 3)
|
||||||
$("#value-div").css("display", "none");
|
$("#value-div").css("display", "none");
|
||||||
if ($(\'#id_discount_type\').val() != 2)
|
if ($(\'#id_discount_type\').val() != 2)
|
||||||
$(\'#behavior_not_exhausted\').hide();
|
$(\'#behavior_not_exhausted\').hide();
|
||||||
|
|
||||||
}
|
}
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$("#id_discount_type").change(function(){discountType();});
|
$("#id_discount_type").change(function(){discountType();});
|
||||||
@ -261,7 +292,7 @@ class AdminDiscounts extends AdminTab
|
|||||||
<input size="33" type="text" name="description_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'description', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
|
<input size="33" type="text" name="description_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'description', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
|
||||||
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer"> </span></span>
|
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer"> </span></span>
|
||||||
<p class="clear">'.$this->l('Will appear in cart next to voucher code').'</p>
|
<p class="clear">'.$this->l('Will appear in cart next to voucher code').'</p>
|
||||||
</div>';
|
</div>';
|
||||||
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'description', 'description');
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'description', 'description');
|
||||||
echo ' </div>
|
echo ' </div>
|
||||||
<div class="clear" / >
|
<div class="clear" / >
|
||||||
@ -318,6 +349,15 @@ class AdminDiscounts extends AdminTab
|
|||||||
<label class="t" for="cumulable_reduction_on"> '.$this->l('Cumulative with price reductions').'</label>
|
<label class="t" for="cumulable_reduction_on"> '.$this->l('Cumulative with price reductions').'</label>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label for="discount_custom_group">'.$this->l('Limiter à un segment :').'</label>
|
||||||
|
<div class="margin-form">
|
||||||
|
<select name="discount_custom_group" id="discount_custom_group" style="vertical-align: middle; width: 250px;">
|
||||||
|
'.$obj->custom_group_select.'
|
||||||
|
</select>
|
||||||
|
<p>'.$this->l('La segmentation liée est mis à jour toutes les nuits').'</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<label>'.$this->l('To be used by:').' </label>
|
<label>'.$this->l('To be used by:').' </label>
|
||||||
<div class="margin-form">
|
<div class="margin-form">
|
||||||
<input type="hidden" name="id_customer" value="0">
|
<input type="hidden" name="id_customer" value="0">
|
||||||
@ -330,13 +370,13 @@ class AdminDiscounts extends AdminTab
|
|||||||
</optgroup>
|
</optgroup>
|
||||||
</select><br />'.$this->l('Filter:').' <input type="text" size="25" name="filter" id="filter" onkeyup="fillCustomersAjax();" class="space" value="" />
|
</select><br />'.$this->l('Filter:').' <input type="text" size="25" name="filter" id="filter" onkeyup="fillCustomersAjax();" class="space" value="" />
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var formDiscount = document.layers ? document.forms.discount : document.discount;
|
var formDiscount = document.layers ? document.forms.discount : document.discount;
|
||||||
function fillCustomersAjax()
|
function fillCustomersAjax()
|
||||||
{
|
{
|
||||||
var filterValue = \''.(($value = (int)($this->getFieldValue($obj, 'id_customer'))) ? '0_'.$value : (($value = (int)($this->getFieldValue($obj, 'id_group'))) ? '1_'.$value : '')).'\';
|
var filterValue = \''.(($value = (int)($this->getFieldValue($obj, 'id_customer'))) ? '0_'.$value : (($value = (int)($this->getFieldValue($obj, 'id_group'))) ? '1_'.$value : '')).'\';
|
||||||
if ($(\'#filter\').val())
|
if ($(\'#filter\').val())
|
||||||
filterValue = $(\'#filter\').val();
|
filterValue = $(\'#filter\').val();
|
||||||
|
|
||||||
$.getJSON("'.dirname($currentIndex).'/ajax.php",{ajaxDiscountCustomers:1,filter:filterValue},
|
$.getJSON("'.dirname($currentIndex).'/ajax.php",{ajaxDiscountCustomers:1,filter:filterValue},
|
||||||
function(obj) {
|
function(obj) {
|
||||||
var groups_length = obj.groups.length;
|
var groups_length = obj.groups.length;
|
||||||
@ -346,7 +386,7 @@ class AdminDiscounts extends AdminTab
|
|||||||
if (obj.customers.length == 0)
|
if (obj.customers.length == 0)
|
||||||
customers_length = 1;
|
customers_length = 1;
|
||||||
formDiscount.id_target.length = 1 + customers_length + groups_length;
|
formDiscount.id_target.length = 1 + customers_length + groups_length;
|
||||||
|
|
||||||
if (obj.groups.length == 0)
|
if (obj.groups.length == 0)
|
||||||
{
|
{
|
||||||
formDiscount.id_target.options[1].value = -1;
|
formDiscount.id_target.options[1].value = -1;
|
||||||
@ -368,13 +408,13 @@ class AdminDiscounts extends AdminTab
|
|||||||
formDiscount.id_target.options[50].className = "groups_filtered";
|
formDiscount.id_target.options[50].className = "groups_filtered";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.customers.length == 0)
|
if (obj.customers.length == 0)
|
||||||
{
|
{
|
||||||
formDiscount.id_target.options[groups_length+1].value = -1;
|
formDiscount.id_target.options[groups_length+1].value = -1;
|
||||||
formDiscount.id_target.options[groups_length+1].text = \''.$this->l('No match found').'\';
|
formDiscount.id_target.options[groups_length+1].text = \''.$this->l('No match found').'\';
|
||||||
formDiscount.id_target.options[groups_length+1].className = "customers_filtered";
|
formDiscount.id_target.options[groups_length+1].className = "customers_filtered";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; i < obj.customers.length && i < 50; i++)
|
for (i = 0; i < obj.customers.length && i < 50; i++)
|
||||||
@ -406,11 +446,11 @@ class AdminDiscounts extends AdminTab
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
fillCustomersAjax();
|
fillCustomersAjax();
|
||||||
</script>
|
</script>
|
||||||
</div><br />';
|
</div><br />';
|
||||||
includeDatepicker(array('date_from', 'date_to'), true);
|
includeDatepicker(array('date_from', 'date_to'), true);
|
||||||
echo '
|
echo '
|
||||||
<label>'.$this->l('From:').' </label>
|
<label>'.$this->l('From:').' </label>
|
||||||
<div class="margin-form">
|
<div class="margin-form">
|
||||||
<input type="text" size="20" id="date_from" name="date_from" value="'.($this->getFieldValue($obj, 'date_from') ? htmlentities($this->getFieldValue($obj, 'date_from'), ENT_COMPAT, 'UTF-8') : date('Y-m-d H:i:s')).'" /> <sup>*</sup>
|
<input type="text" size="20" id="date_from" name="date_from" value="'.($this->getFieldValue($obj, 'date_from') ? htmlentities($this->getFieldValue($obj, 'date_from'), ENT_COMPAT, 'UTF-8') : date('Y-m-d H:i:s')).'" /> <sup>*</sup>
|
||||||
@ -466,7 +506,7 @@ class AdminDiscounts extends AdminTab
|
|||||||
|
|
||||||
$level = $current['infos']['level_depth'] + 1;
|
$level = $current['infos']['level_depth'] + 1;
|
||||||
|
|
||||||
if(!empty($indexedCategories)){
|
if(!empty($indexedCategories)){
|
||||||
echo '
|
echo '
|
||||||
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
||||||
<td>
|
<td>
|
||||||
@ -485,8 +525,8 @@ class AdminDiscounts extends AdminTab
|
|||||||
echo '
|
echo '
|
||||||
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" name="categoryBox[]"
|
<input type="checkbox" name="categoryBox[]"
|
||||||
class="categoryBox'.($id_category_default == $id_category ? ' id_category_default' : '').'"
|
class="categoryBox'.($id_category_default == $id_category ? ' id_category_default' : '').'"
|
||||||
id="categoryBox_'.$id_category.'" value="'.$id_category.'" '. (1 == $id_category ? 'checked="checked" ' : '') .'/>
|
id="categoryBox_'.$id_category.'" value="'.$id_category.'" '. (1 == $id_category ? 'checked="checked" ' : '') .'/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
440
modules/ant_customgroup/AdminAntCustomgroup.php
Normal file
440
modules/ant_customgroup/AdminAntCustomgroup.php
Normal file
@ -0,0 +1,440 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once(_PS_MODULE_DIR_.'/ant_customgroup/models/CustomGroup.php');
|
||||||
|
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
|
||||||
|
|
||||||
|
class AdminAntCustomgroup extends AdminTab
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $_html;
|
||||||
|
public $module_name;
|
||||||
|
public $config_tab;
|
||||||
|
public $controller;
|
||||||
|
public $helperForm;
|
||||||
|
public $_object;
|
||||||
|
|
||||||
|
public function __construct($config_tab = true)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->_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 .='<div class="clearfix"></div>';
|
||||||
|
$this->_addJs();
|
||||||
|
$this->_html .= $this->helperForm->renderScript();
|
||||||
|
echo $this->_html;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _addJs()
|
||||||
|
{
|
||||||
|
$this->helperForm->_js .= '<script type="text/javascript"></script>';
|
||||||
|
}
|
||||||
|
|
||||||
|
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 .='
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-title">
|
||||||
|
<h2><span class="text-rose anticon anticon-list"></span> '.$this->l('Liste des groupes').'</h2>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-content">
|
||||||
|
<table class="table table-custombordered" style="width: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="text-left">'.$this->l('ID').'</th>
|
||||||
|
<th class="text-left">'.$this->l('Name').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Subscription days').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Last order days').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Retention days').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Minimum order amount').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Active').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Nb').'</th>
|
||||||
|
<th class="text-center">'.$this->l('Action').'</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>';
|
||||||
|
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 = '<span class="anticon anticon-minus text-orange"></span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($custom_group['register_date'] == 0) {
|
||||||
|
$register_date = '<span class="anticon anticon-minus text-orange"></span>';
|
||||||
|
} else {
|
||||||
|
$register_date = $custom_group['register_date'] . " jours";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($custom_group['last_order_date'] == 0) {
|
||||||
|
$last_order_date = '<span class="anticon anticon-minus text-orange"></span>';
|
||||||
|
} else {
|
||||||
|
$last_order_date = $custom_group['last_order_date'] . " jours";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($custom_group['nb_retention_days'] == 0) {
|
||||||
|
$nb_retention_days = '<span class="anticon anticon-minus text-orange"></span>';
|
||||||
|
} 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 .='
|
||||||
|
<tr>
|
||||||
|
<td valign="middle" align="left">#'.$custom_group['id_custom_group'].'</td>
|
||||||
|
<td valign="middle" align="left"><b>'.$custom_group['name'].'</b></td>
|
||||||
|
<td valign="middle" align="center">'.$register_date.'</td>
|
||||||
|
<td valign="middle" align="center">'.$last_order_date.'</td>
|
||||||
|
<td valign="middle" align="center">'.$nb_retention_days.'</td>
|
||||||
|
<td valign="middle" align="center">'.$minimum_order_amount.'</td>
|
||||||
|
<td align="center">'.((int)$custom_group['active']?'<span class="anticon anticon-checkmark text-green-light"></span>':'<span class="anticon anticon-cross text-rose"></span>').'</td>
|
||||||
|
<td valign="middle" align="center">'.$customer_number.'</td>
|
||||||
|
<td valign="middle" align="center">
|
||||||
|
<div class="input-group-btn" role="group" aria-label="...">
|
||||||
|
<a href="'.$_current_index.'&loadGroup=1&id='.$custom_group['id_custom_group'].'" class="btn btn-default"><span class="anticon anticon-pencil2"></span></a>
|
||||||
|
<a href="'.$_current_index.'&refreshGroup=1&id='.$custom_group['id_custom_group'].'" class="btn btn-default"><span class="anticon anticon-loop2"></span></a>
|
||||||
|
<a href="'.$_current_index.'&deleteGroup=1&id='.$custom_group['id_custom_group'].'" class="btn btn-default"><span class="anticon anticon-bin"></span></a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>';
|
||||||
|
}
|
||||||
|
$this->_html .='
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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' => '<span class="text-rose anticon anticon-make-group"></span> '.$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' => '<span class="anticon anticon-info"></span> Informations',
|
||||||
|
'info_html' => '
|
||||||
|
<p>L\'inscrit est ajouté au groupe une fois la condition requise et en ressort lorsqu\'il depasse cette date</p>
|
||||||
|
<p>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).<br>
|
||||||
|
Par exemple :</p>
|
||||||
|
<ul>
|
||||||
|
<li>Nb jrs depuis l\'inscription : 8</li>
|
||||||
|
<li>Nombre de jours de rétention : 31</li>
|
||||||
|
</ul>
|
||||||
|
<p>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.
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li>Nb jrs depuis l\'inscription : 8</li>
|
||||||
|
<li>Nombre de jours de rétention : 0</li>
|
||||||
|
</ul>
|
||||||
|
<p>Tous les membres inscrits depuis 8 jours et plus peuvent utiliser le code.</p>
|
||||||
|
<p></p>'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'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();
|
||||||
|
}
|
||||||
|
}
|
116
modules/ant_customgroup/ant_customgroup.php
Normal file
116
modules/ant_customgroup/ant_customgroup.php
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
513
modules/ant_customgroup/models/CustomGroup.php
Normal file
513
modules/ant_customgroup/models/CustomGroup.php
Normal file
@ -0,0 +1,513 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class CustomGroup extends ObjectModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public $name;
|
||||||
|
public $register_date;
|
||||||
|
public $last_order_date;
|
||||||
|
public $nb_retention_days;
|
||||||
|
public $minimum_order_amount;
|
||||||
|
public $customer_order_stats;
|
||||||
|
public $sales;
|
||||||
|
public $active;
|
||||||
|
public $date_add;
|
||||||
|
public $date_upd;
|
||||||
|
|
||||||
|
protected $fieldsRequired = array('name', 'nb_retention_days');
|
||||||
|
protected $fieldsValidate = array(
|
||||||
|
'name' => 'isName',
|
||||||
|
'register_date' => 'isUnsignedId',
|
||||||
|
'last_order_date' => 'isUnsignedId',
|
||||||
|
'nb_retention_days' => 'isUnsignedId',
|
||||||
|
'minimum_order_amount' => 'isFloat',
|
||||||
|
'active' => 'isBool',
|
||||||
|
'date_add' => 'isDate',
|
||||||
|
'date_upd' => 'isDate',
|
||||||
|
);
|
||||||
|
|
||||||
|
protected $table = 'custom_group';
|
||||||
|
protected $identifier = 'id_custom_group';
|
||||||
|
|
||||||
|
|
||||||
|
public function getFields()
|
||||||
|
{
|
||||||
|
parent::validateFields();
|
||||||
|
|
||||||
|
$fields['name'] = pSQL($this->name);
|
||||||
|
$fields['register_date'] = (int)$this->register_date;
|
||||||
|
$fields['last_order_date'] = (int)$this->last_order_date;
|
||||||
|
$fields['nb_retention_days'] = (int)$this->nb_retention_days;
|
||||||
|
$fields['minimum_order_amount'] = (float)$this->minimum_order_amount;
|
||||||
|
$fields['active'] = (int)$this->active;
|
||||||
|
$fields['date_add'] = pSQL($this->date_add);
|
||||||
|
$fields['date_upd'] = pSQL($this->date_upd);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$res = parent::delete();
|
||||||
|
if ($res) {
|
||||||
|
return (Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'custom_group_customer`
|
||||||
|
WHERE `id_custom_group` = ' . (int)$this->id) &&
|
||||||
|
// Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'custom_group_order_stats`
|
||||||
|
// WHERE `id_custom_group` = ' . (int)$this->id) &&
|
||||||
|
// Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'custom_group_sales`
|
||||||
|
// WHERE `id_custom_group` = ' . (int)$this->id) &&
|
||||||
|
Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'custom_group_discount`
|
||||||
|
WHERE `id_custom_group` = ' . (int)$this->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get groups
|
||||||
|
* @param $only_active Bool get only active groups
|
||||||
|
* @return Array Groups
|
||||||
|
*/
|
||||||
|
public static function getGroups($only_active = true)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->executeS('
|
||||||
|
SELECT *
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group` cg
|
||||||
|
WHERE 1
|
||||||
|
' . ($only_active ? 'AND cg.`active` = 1' : '') . '
|
||||||
|
ORDER BY cg.id_custom_group;
|
||||||
|
');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
if (parent::save()) {
|
||||||
|
$return = true;
|
||||||
|
if (isset($this->customer_order_stats)) {
|
||||||
|
$return = $return && self::setOrderStats($this->id, $this->customer_order_stats);
|
||||||
|
}
|
||||||
|
if (isset($this->sales)) {
|
||||||
|
$return = $return && self::setSales($this->id, $this->sales);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the custom group order stats is selected for the given custom group
|
||||||
|
* @param $id_custom_group integer
|
||||||
|
* @return Array Customer order stats Ids
|
||||||
|
*/
|
||||||
|
public static function getOrderStatsIds($id_custom_group)
|
||||||
|
{
|
||||||
|
if (!isset($id_custom_group)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Db::getInstance()->executeS('
|
||||||
|
SELECT id_order_stats
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group_order_stats`
|
||||||
|
WHERE id_custom_group = ' . (int)$id_custom_group . '
|
||||||
|
');
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$tmparray = array();
|
||||||
|
foreach ($result as $row) {
|
||||||
|
$tmparray[] = (int)$row['id_order_stats'];
|
||||||
|
}
|
||||||
|
$result = $tmparray;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the custom group order stats is selected for the given custom group
|
||||||
|
* @param $id_custom_group integer
|
||||||
|
* @return Array Customer order stats Ids
|
||||||
|
*/
|
||||||
|
public static function getSalesIds($id_custom_group)
|
||||||
|
{
|
||||||
|
if (!isset($id_custom_group)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Db::getInstance()->executeS('
|
||||||
|
SELECT id_sale
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group_sales`
|
||||||
|
WHERE id_custom_group = ' . (int)$id_custom_group . '
|
||||||
|
');
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$tmparray = array();
|
||||||
|
foreach ($result as $row) {
|
||||||
|
$tmparray[] = (int)$row['id_sale'];
|
||||||
|
}
|
||||||
|
$result = $tmparray;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setOrderStats($id_custom_group, $custom_group_order_stats_array)
|
||||||
|
{
|
||||||
|
if (!isset($id_custom_group)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!is_array($custom_group_order_stats_array)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Db::getInstance()->Execute('DELETE
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group_order_stats`
|
||||||
|
WHERE id_custom_group = ' . (int)$id_custom_group)
|
||||||
|
) {
|
||||||
|
foreach ($custom_group_order_stats_array as $custom_group_order_stats_id) {
|
||||||
|
Db::getInstance()->ExecuteS('INSERT INTO `' . _DB_PREFIX_ . 'custom_group_order_stats`
|
||||||
|
VALUES (' .
|
||||||
|
(int)$id_custom_group . ',' .
|
||||||
|
(int)$custom_group_order_stats_id .
|
||||||
|
')'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setSales($id_custom_group, $custom_group_sales_array)
|
||||||
|
{
|
||||||
|
if (!isset($id_custom_group)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!is_array($custom_group_sales_array)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Db::getInstance()->Execute('DELETE
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group_sales`
|
||||||
|
WHERE id_custom_group = ' . (int)$id_custom_group)
|
||||||
|
) {
|
||||||
|
foreach ($custom_group_sales_array as $custom_group_sale_id) {
|
||||||
|
Db::getInstance()->ExecuteS('INSERT INTO `' . _DB_PREFIX_ . 'custom_group_sales`
|
||||||
|
VALUES (' .
|
||||||
|
(int)$id_custom_group . ',' .
|
||||||
|
(int)$custom_group_sale_id .
|
||||||
|
')'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refreshCustomGroup()
|
||||||
|
{
|
||||||
|
return self::refreshCustomGroupStatic($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function refreshCustomGroupStatic($id_custom_group)
|
||||||
|
{
|
||||||
|
$where_clause = "";
|
||||||
|
$join_clause = "";
|
||||||
|
if (!isset($id_custom_group)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$customGroup = new CustomGroup((int)$id_custom_group);
|
||||||
|
|
||||||
|
if (Validate::isLoadedObject($customGroup)) {
|
||||||
|
$retention_days = 0;
|
||||||
|
if ($customGroup->nb_retention_days > 0) {
|
||||||
|
$retention_days = $customGroup->nb_retention_days;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the group is linked to orders data, we get the id_customer array from here.
|
||||||
|
if ($customGroup->last_order_date != 0 OR $customGroup->minimum_order_amount > 0.0) {
|
||||||
|
if($retention_days != 0) {
|
||||||
|
if ($customGroup->last_order_date != 0) {
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), o.date_add) < ' . ((int)$customGroup->last_order_date + (int)$retention_days);
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), o.date_add) > ' . (int)$customGroup->last_order_date;
|
||||||
|
}
|
||||||
|
if ($customGroup->register_date != 0) {
|
||||||
|
$join_clause .= ' JOIN `' . _DB_PREFIX_ . 'customer` pc ON pc.id_customer = o.id_customer ';
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) < ' . ((int)$customGroup->register_date + (int)$retention_days);
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) > ' . ((int)$customGroup->register_date);
|
||||||
|
}
|
||||||
|
}elseif($retention_days == 0){
|
||||||
|
if ($customGroup->last_order_date != 0) {
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), o.date_add) > ' . (int)$customGroup->last_order_date;
|
||||||
|
}
|
||||||
|
if ($customGroup->register_date != 0) {
|
||||||
|
$join_clause .= ' JOIN `' . _DB_PREFIX_ . 'customer` pc ON pc.id_customer = o.id_customer ';
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) > ' . (int)$customGroup->register_date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($customGroup->minimum_order_amount > 0.0) {
|
||||||
|
$where_clause .= ' AND o.total_paid_real > ' . round($customGroup->minimum_order_amount, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = 'SELECT o.id_customer
|
||||||
|
FROM `' . _DB_PREFIX_ . 'orders` o
|
||||||
|
' . $join_clause . '
|
||||||
|
WHERE o.valid = 1
|
||||||
|
' . $where_clause . '
|
||||||
|
GROUP BY o.id_customer';
|
||||||
|
// echo $query."\n";
|
||||||
|
$customer_ids = Db::getInstance()->executeS($query);
|
||||||
|
} else {
|
||||||
|
if($retention_days != 0) {
|
||||||
|
if ($customGroup->register_date != 0) {
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) < ' . ((int)$customGroup->register_date + (int)$retention_days);
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) > ' . ((int)$customGroup->register_date);
|
||||||
|
}
|
||||||
|
} elseif ($retention_days == 0){
|
||||||
|
if ($customGroup->register_date != 0) {
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) > ' . (int)$customGroup->register_date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$query = 'SELECT pc.id_customer
|
||||||
|
FROM `' . _DB_PREFIX_ . 'customer` pc
|
||||||
|
' . $join_clause . '
|
||||||
|
WHERE 1
|
||||||
|
' . $where_clause . '';
|
||||||
|
// echo $query."\n";
|
||||||
|
$customer_ids = Db::getInstance()->executeS($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
$batch_size = 1000;
|
||||||
|
$buffer_key_values = array();
|
||||||
|
if (Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'custom_group_customer`
|
||||||
|
WHERE id_custom_group = ' . (int)$customGroup->id)
|
||||||
|
) {
|
||||||
|
$insert = 'INSERT INTO `' . _DB_PREFIX_ . 'custom_group_customer` (id_custom_group, id_customer) VALUES ';
|
||||||
|
for ($i = 0; $i < count($customer_ids); $i++) {
|
||||||
|
$buffer_key_values[] = '(' . $customGroup->id . ',' . $customer_ids[$i]['id_customer'] . ')';
|
||||||
|
|
||||||
|
if (($i % $batch_size) == 0 and $i > 0) {
|
||||||
|
Db::getInstance()->Execute($insert . implode(',', $buffer_key_values));
|
||||||
|
$buffer_key_values = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($buffer_key_values) > 0) {
|
||||||
|
Db::getInstance()->Execute($insert . implode(',', $buffer_key_values));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refreshCustomers()
|
||||||
|
{
|
||||||
|
return self::refreshCustomersStatic($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function refreshCustomersStatic($id_custom_group)
|
||||||
|
{
|
||||||
|
$where_clause = "";
|
||||||
|
$join_clause = "";
|
||||||
|
if (!isset($id_custom_group)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$customGroup = new CustomGroup((int)$id_custom_group);
|
||||||
|
|
||||||
|
if (Validate::isLoadedObject($customGroup)) {
|
||||||
|
$retention_days = 0;
|
||||||
|
if ($customGroup->nb_retention_days > 0) {
|
||||||
|
$retention_days = $customGroup->nb_retention_days;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the group is linked to orders data, we get the id_customer array from here.
|
||||||
|
if ((CustomGroup::getSalesIds($customGroup->id))
|
||||||
|
OR $customGroup->last_order_date != 0
|
||||||
|
OR $customGroup->minimum_order_amount > 0.0
|
||||||
|
) {
|
||||||
|
if($retention_days != 0) {
|
||||||
|
if ($customGroup->last_order_date != 0) {
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), o.date_add) < ' . ((int)$customGroup->last_order_date + (int)$retention_days);
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), o.date_add) > ' . (int)$customGroup->last_order_date;
|
||||||
|
}
|
||||||
|
if ($customGroup->register_date != 0) {
|
||||||
|
$join_clause .= ' JOIN `' . _DB_PREFIX_ . 'customer` pc ON pc.id_customer = o.id_customer ';
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) < ' . ((int)$customGroup->register_date + (int)$retention_days);
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) > ' . ((int)$customGroup->register_date);
|
||||||
|
}
|
||||||
|
}elseif($retention_days == 0){
|
||||||
|
if ($customGroup->last_order_date != 0) {
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), o.date_add) > ' . (int)$customGroup->last_order_date;
|
||||||
|
}
|
||||||
|
if ($customGroup->register_date != 0) {
|
||||||
|
$join_clause .= ' JOIN `' . _DB_PREFIX_ . 'customer` pc ON pc.id_customer = o.id_customer ';
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) > ' . (int)$customGroup->register_date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($customGroup->minimum_order_amount > 0.0) {
|
||||||
|
$where_clause .= ' AND o.total_paid_real > ' . round($customGroup->minimum_order_amount, 2);
|
||||||
|
}
|
||||||
|
if ((CustomGroup::getOrderStatsIds($customGroup->id))) {
|
||||||
|
$join_clause .= ' JOIN `' . _DB_PREFIX_ . 'customer_order_stats` cos
|
||||||
|
ON cos.id_customer = o.id_customer';
|
||||||
|
$where_clause .= ' AND cos.id_order_stats IN (' . implode(',', CustomGroup::getOrderStatsIds($customGroup->id)) . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (CustomGroup::getSalesIds($customGroup->id)) {
|
||||||
|
$query = 'SELECT o.id_customer
|
||||||
|
FROM `' . _DB_PREFIX_ . 'product_ps_cache` ppsc
|
||||||
|
JOIN `' . _DB_PREFIX_ . 'order_detail` od ON od.product_id = ppsc.id_product
|
||||||
|
JOIN `' . _DB_PREFIX_ . 'orders` o ON o.id_order = od.id_order
|
||||||
|
' . $join_clause . '
|
||||||
|
WHERE ppsc.id_sale IN (' . implode(',', CustomGroup::getSalesIds($customGroup->id)) . ' )
|
||||||
|
AND o.valid = 1
|
||||||
|
' . $where_clause . '
|
||||||
|
GROUP BY o.id_customer
|
||||||
|
';
|
||||||
|
//echo $query."\n";
|
||||||
|
$customer_ids = Db::getInstance()->executeS($query);
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$query = 'SELECT o.id_customer
|
||||||
|
FROM `' . _DB_PREFIX_ . 'orders` o
|
||||||
|
' . $join_clause . '
|
||||||
|
WHERE o.valid = 1
|
||||||
|
' . $where_clause . '
|
||||||
|
GROUP BY o.id_customer
|
||||||
|
';
|
||||||
|
//echo $query."\n";
|
||||||
|
$customer_ids = Db::getInstance()->executeS($query);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((CustomGroup::getOrderStatsIds($customGroup->id))) {
|
||||||
|
$join_clause .= ' JOIN `' . _DB_PREFIX_ . 'customer_order_stats` cos
|
||||||
|
ON cos.id_customer = pc.id_customer';
|
||||||
|
$where_clause .= ' AND cos.id_order_stats IN (' . implode(',', CustomGroup::getOrderStatsIds($customGroup->id)) . ')';
|
||||||
|
}
|
||||||
|
if($retention_days != 0) {
|
||||||
|
if ($customGroup->register_date != 0) {
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) < ' . ((int)$customGroup->register_date + (int)$retention_days);
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) > ' . ((int)$customGroup->register_date);
|
||||||
|
}
|
||||||
|
}elseif($retention_days == 0){
|
||||||
|
if ($customGroup->register_date != 0) {
|
||||||
|
$where_clause .= ' AND DATEDIFF(CURDATE(), pc.date_add) > ' . (int)$customGroup->register_date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$query = 'SELECT pc.id_customer
|
||||||
|
FROM `' . _DB_PREFIX_ . 'customer` pc
|
||||||
|
' . $join_clause . '
|
||||||
|
WHERE 1
|
||||||
|
' . $where_clause . '
|
||||||
|
';
|
||||||
|
//echo $query."\n";
|
||||||
|
$customer_ids = Db::getInstance()->executeS($query);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$batch_size = 1000;
|
||||||
|
$buffer_key_values = array();
|
||||||
|
if (Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'custom_group_customer`
|
||||||
|
WHERE id_custom_group = ' . (int)$customGroup->id)
|
||||||
|
) {
|
||||||
|
$insert = 'INSERT INTO `' . _DB_PREFIX_ . 'custom_group_customer` (id_custom_group, id_customer) VALUES ';
|
||||||
|
for ($i = 0; $i < count($customer_ids); $i++) {
|
||||||
|
$buffer_key_values[] = '(' . $customGroup->id . ',' . $customer_ids[$i]['id_customer'] . ')';
|
||||||
|
|
||||||
|
if (($i % $batch_size) == 0 and $i > 0) {
|
||||||
|
Db::getInstance()->Execute($insert . implode(',', $buffer_key_values));
|
||||||
|
$buffer_key_values = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($buffer_key_values) > 0) {
|
||||||
|
Db::getInstance()->Execute($insert . implode(',', $buffer_key_values));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCount($id_custom_group)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->getValue("SELECT COUNT(id_customer)
|
||||||
|
FROM `" . _DB_PREFIX_ . "custom_group_customer`
|
||||||
|
WHERE id_custom_group = " . (int)$id_custom_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function inGroup($id_custom_group, $id_customer)
|
||||||
|
{
|
||||||
|
return (Db::getInstance()->getValue('SELECT count(*)
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group_customer`
|
||||||
|
WHERE id_customer = ' . (int)$id_customer . '
|
||||||
|
AND id_custom_group = ' . (int)$id_custom_group) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCustomers($id_custom_group)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->executeS("SELECT id_customer
|
||||||
|
FROM `" . _DB_PREFIX_ . "custom_group_customer`
|
||||||
|
WHERE id_custom_group = " . (int)$id_custom_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isLinkedToDiscount($id_custom_group, $id_discount)
|
||||||
|
{
|
||||||
|
return (Db::getInstance()->getValue('SELECT count(*)
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group_discount`
|
||||||
|
WHERE id_discount = ' . (int)$id_discount . '
|
||||||
|
AND id_custom_group = ' . (int)$id_custom_group) > 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCustomGroupIdByDiscount($id_discount)
|
||||||
|
{
|
||||||
|
/*echo 'getCustomGroupIdByDiscount'.$id_discount.' SELECT id_custom_group
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group_discount`
|
||||||
|
WHERE id_discount = ' . (int)$id_discount;*/
|
||||||
|
if ($id_custom_group = Db::getInstance()->getValue('SELECT id_custom_group
|
||||||
|
FROM `' . _DB_PREFIX_ . 'custom_group_discount`
|
||||||
|
WHERE id_discount = ' . (int)$id_discount)
|
||||||
|
) {
|
||||||
|
return (int)$id_custom_group;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function linkToDiscount($id_custom_group, $id_discount)
|
||||||
|
{
|
||||||
|
if (Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'custom_group_discount`
|
||||||
|
WHERE id_discount = ' . (int)$id_discount)
|
||||||
|
) {
|
||||||
|
if (isset($id_custom_group)) {
|
||||||
|
return Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'custom_group_discount`
|
||||||
|
(id_custom_group, id_discount) VALUES
|
||||||
|
(' . (int)$id_custom_group . ',' . (int)$id_discount . ')');
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isValidDiscount($id_discount, $id_customer)
|
||||||
|
{
|
||||||
|
if (!isset($id_discount) OR !isset($id_customer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($id_custom_group = self::getCustomGroupIdByDiscount($id_discount)) {
|
||||||
|
//echo 'isValidDiscount'.$id_custom_group." - ".$id_customer.self::inGroup($id_custom_group,$id_customer);
|
||||||
|
return self::inGroup($id_custom_group, $id_customer);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -859,35 +859,54 @@ class Cart extends CartCore {
|
|||||||
return Tools::displayError('This voucher has expired.');
|
return Tools::displayError('This voucher has expired.');
|
||||||
if (sizeof($discounts) >= 1 AND $checkCartDiscount)
|
if (sizeof($discounts) >= 1 AND $checkCartDiscount)
|
||||||
{
|
{
|
||||||
if (!$discountObj->cumulable)
|
if (!$discountObj->cumulable) {
|
||||||
return Tools::displayError('This voucher is not valid with other current discounts.');
|
return Tools::displayError('This voucher is not valid with other current discounts.');
|
||||||
foreach ($discounts as $discount)
|
}
|
||||||
if (!$discount['cumulable'])
|
foreach ($discounts as $discount) {
|
||||||
|
if (!$discount['cumulable']) {
|
||||||
return Tools::displayError('Voucher is not valid with other discounts.');
|
return Tools::displayError('Voucher is not valid with other discounts.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach($discounts as $discount)
|
foreach($discounts as $discount) {
|
||||||
if ($discount['id_discount'] == $discountObj->id)
|
if ($discount['id_discount'] == $discountObj->id) {
|
||||||
return Tools::displayError('This voucher is already in your cart');
|
return Tools::displayError('This voucher is already in your cart');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$groups = Customer::getGroupsStatic($this->id_customer);
|
$groups = Customer::getGroupsStatic($this->id_customer);
|
||||||
|
|
||||||
if (($discountObj->id_customer OR $discountObj->id_group) AND ((($this->id_customer != $discountObj->id_customer) OR ($this->id_customer == 0)) AND !in_array($discountObj->id_group, $groups)))
|
if (($discountObj->id_customer OR $discountObj->id_group) AND ((($this->id_customer != $discountObj->id_customer) OR ($this->id_customer == 0)) AND !in_array($discountObj->id_group, $groups)))
|
||||||
{
|
{
|
||||||
if (!$cookie->isLogged())
|
if (!$cookie->isLogged()){
|
||||||
return Tools::displayError('You cannot use this voucher.').' - '.Tools::displayError('Please log in.');
|
return Tools::displayError('You cannot use this voucher.').' - '.Tools::displayError('Please log in.');
|
||||||
|
}
|
||||||
return Tools::displayError('You cannot use this voucher.');
|
return Tools::displayError('You cannot use this voucher.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override Antadis - check in custom group
|
||||||
|
if (!class_exists('CustomGroup')) {
|
||||||
|
require_once(_PS_MODULE_DIR_.'ant_customgroup/models/CustomGroup.php');
|
||||||
|
}
|
||||||
|
if (!CustomGroup::isValidDiscount($discountObj->id, $this->id_customer)) {
|
||||||
|
return Tools::displayError('This voucher has already been used or is disabled.');
|
||||||
|
}
|
||||||
|
// @End override
|
||||||
|
|
||||||
$onlyProductWithDiscount = false;
|
$onlyProductWithDiscount = false;
|
||||||
if (!$discountObj->cumulable_reduction)
|
if (!$discountObj->cumulable_reduction)
|
||||||
{
|
{
|
||||||
foreach ($products as $product)
|
foreach ($products as $product) {
|
||||||
if ($product['reduction_applies'] OR $product['on_sale'])
|
if ($product['reduction_applies'] OR $product['on_sale']) {
|
||||||
$onlyProductWithDiscount = true;
|
$onlyProductWithDiscount = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!$discountObj->cumulable_reduction AND $onlyProductWithDiscount)
|
|
||||||
|
if (!$discountObj->cumulable_reduction AND $onlyProductWithDiscount) {
|
||||||
return Tools::displayError('This voucher is not valid for marked or reduced products.');
|
return Tools::displayError('This voucher is not valid for marked or reduced products.');
|
||||||
|
}
|
||||||
$total_cart = 0;
|
$total_cart = 0;
|
||||||
|
|
||||||
foreach($products AS $product) {
|
foreach($products AS $product) {
|
||||||
|
@ -70,7 +70,7 @@ class Discount extends DiscountCore
|
|||||||
|
|
||||||
$categories = parent::getCategories($id_discount);
|
$categories = parent::getCategories($id_discount);
|
||||||
// if only root category is checked return all categories.
|
// if only root category is checked return all categories.
|
||||||
if ( count($categories == 1) ){
|
if ( count($categories) == 1 ){
|
||||||
$rootCategory = Category::getRootCategory();
|
$rootCategory = Category::getRootCategory();
|
||||||
if ( $categories[0]['id_category'] == (int)$rootCategory->id ){
|
if ( $categories[0]['id_category'] == (int)$rootCategory->id ){
|
||||||
$result = Db::getInstance()->ExecuteS('SELECT id_category FROM '._DB_PREFIX_.'category');
|
$result = Db::getInstance()->ExecuteS('SELECT id_category FROM '._DB_PREFIX_.'category');
|
||||||
|
Loading…
Reference in New Issue
Block a user