2016-11-08 14:58:29 +01:00
|
|
|
<?php
|
|
|
|
if(!defined('_PS_VERSION_')) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
2016-12-12 15:35:45 +01:00
|
|
|
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
|
2016-11-08 14:58:29 +01:00
|
|
|
require_once(PS_ADMIN_DIR . '/helpers/HelperForm.php');
|
|
|
|
require_once(PS_ADMIN_DIR . '/helpers/HelperList.php');
|
|
|
|
|
|
|
|
class AdminAntConfigurations extends AdminTab
|
|
|
|
{
|
|
|
|
public function postProcess() {
|
2016-11-09 11:19:05 +01:00
|
|
|
global $cookie;
|
2016-11-08 14:58:29 +01:00
|
|
|
if(Tools::isSubmit('submitProductSaleCache')) {
|
2016-11-23 16:33:55 +01:00
|
|
|
$fileName = 'cron_sale_cache.php';
|
|
|
|
$output = shell_exec("ps -ax | grep $fileName | wc -l");
|
2016-11-08 14:58:29 +01:00
|
|
|
$hour = (int) date('H');
|
|
|
|
$min = (int) date('i');
|
2016-12-12 15:35:45 +01:00
|
|
|
if($output > 2){
|
|
|
|
HelperFormBootstrap::echoError($this->l('Association automatique en cours, réessayez plus tard'));
|
|
|
|
}elseif ($hour%3 == 0 && $min <= 20 && $min >= 10 ){
|
|
|
|
HelperFormBootstrap::echoError($this->l('Association automatique en cours, réessayez plus tard'));
|
2016-11-08 14:58:29 +01:00
|
|
|
} else {
|
|
|
|
$min_id_product = Db::getInstance()->getValue('
|
|
|
|
SELECT MIN(`id_product`) FROM `'._DB_PREFIX_.'product` WHERE `date_add` > DATE_SUB(NOW(), INTERVAL 10 DAY)
|
|
|
|
');
|
|
|
|
if ($min_id_product) {
|
|
|
|
Db::getInstance()->ExecuteS('
|
|
|
|
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
|
|
|
|
WHERE `id_product` >= '.$min_id_product.'
|
|
|
|
');
|
|
|
|
|
|
|
|
Db::getInstance()->ExecuteS('
|
|
|
|
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
|
|
|
|
SELECT p.id_product, IFNULL(
|
|
|
|
(
|
|
|
|
SELECT s.id_sale
|
|
|
|
FROM `'._DB_PREFIX_.'privatesale_category` s
|
|
|
|
WHERE s.`id_category` = p.`id_category_default`
|
|
|
|
LIMIT 1)
|
|
|
|
, 0
|
|
|
|
)
|
|
|
|
FROM `'._DB_PREFIX_.'product` p
|
|
|
|
WHERE p.`id_product` >= '.$min_id_product.'
|
|
|
|
)
|
|
|
|
');
|
2016-11-23 16:33:55 +01:00
|
|
|
// LOG ACTION
|
|
|
|
Db::getInstance()->execute('
|
|
|
|
INSERT INTO `'._DB_PREFIX_.'ant_log`
|
|
|
|
VALUES (
|
|
|
|
DEFAULT,
|
|
|
|
'.(int) $cookie->id_employee.',
|
|
|
|
"'.pSQL('Association manuelle product_ps_cache via Configuration').'",
|
|
|
|
NOW()
|
|
|
|
)
|
|
|
|
');
|
2016-12-12 15:35:45 +01:00
|
|
|
HelperFormBootstrap::echoConfirmation($this->l('Produits associés aux ventes depuis le produit #').$min_id_product);
|
2016-11-08 14:58:29 +01:00
|
|
|
} else {
|
2016-12-12 15:35:45 +01:00
|
|
|
HelperFormBootstrap::echoError($this->l('Pas de produit ajouté depuis 10 jours'));
|
2016-11-08 14:58:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif(Tools::isSubmit('submitCategorySaleCache')) {
|
|
|
|
$id_sale = Tools::getValue('id_sale');
|
|
|
|
if($id_sale) {
|
|
|
|
$sale = new Sale((int)$id_sale);
|
|
|
|
$sale->buildCategoryCache();
|
2016-11-23 16:33:55 +01:00
|
|
|
// LOG ACTION
|
|
|
|
Db::getInstance()->execute('
|
|
|
|
INSERT INTO `'._DB_PREFIX_.'ant_log`
|
|
|
|
VALUES (
|
|
|
|
DEFAULT,
|
|
|
|
'.(int) $cookie->id_employee.',
|
|
|
|
"'.pSQL('Association manuelle categories via Configuration, sale: '.$id_sale).'",
|
|
|
|
NOW()
|
|
|
|
)
|
|
|
|
');
|
2016-12-12 15:35:45 +01:00
|
|
|
HelperFormBootstrap::echoConfirmation($this->l('Categories associés à la vente ').$id_sale);
|
2016-11-08 14:58:29 +01:00
|
|
|
} else {
|
2016-12-12 15:35:45 +01:00
|
|
|
HelperFormBootstrap::echoError($this->l('Veuillez choisir une vente'));
|
2016-11-08 14:58:29 +01:00
|
|
|
}
|
2016-12-12 15:35:45 +01:00
|
|
|
} elseif(Tools::isSubmit('submitUpdateLoyaltyOrders') && $cookie->id_employee == 1) {
|
|
|
|
$nb_credits = $this->updateLoyaltyOrders();
|
|
|
|
HelperFormBootstrap::echoConfirmation($this->l('Credit fidélité mis à jour : ').$nb_credits);
|
2016-12-26 12:31:43 +01:00
|
|
|
} elseif(Tools::isSubmit('submitUpdateCacheSale') && $cookie->id_employee == 1) {
|
|
|
|
$id_category = Tools::getValue('id_category');
|
|
|
|
if($id_category) {
|
|
|
|
Db::getInstance()->ExecuteS('
|
|
|
|
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
|
|
|
|
SELECT p.id_product, IFNULL(
|
|
|
|
(
|
|
|
|
SELECT s.id_sale
|
|
|
|
FROM `'._DB_PREFIX_.'privatesale_category` s
|
|
|
|
WHERE s.`id_category` = p.`id_category_default`
|
|
|
|
LIMIT 1)
|
|
|
|
, 0
|
|
|
|
)
|
|
|
|
FROM `ps_product` p
|
|
|
|
WHERE p.`id_category_default` = '.$id_category.'
|
|
|
|
)
|
|
|
|
');
|
|
|
|
HelperFormBootstrap::echoConfirmation($this->l('Association vente produit mise à jour: #').$id_category);
|
|
|
|
} else {
|
|
|
|
HelperFormBootstrap::echoError($this->l('Veuillez choisir une categorie'));
|
|
|
|
}
|
|
|
|
} elseif(Tools::isSubmit('submitShowProductCacheSale') && $cookie->id_employee == 1) {
|
|
|
|
$id_category = Tools::getValue('id_category');
|
|
|
|
if($id_category) {
|
|
|
|
$products_ids = array();
|
|
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
|
|
SELECT p.id_product
|
|
|
|
FROM `ps_product` p
|
|
|
|
WHERE p.`id_category_default` = '.$id_category.'
|
|
|
|
') as $row) {
|
|
|
|
$products_ids[(int)$row['id_product']] = (int)$row['id_product'];
|
|
|
|
}
|
|
|
|
$result = implode(', ',$products_ids);
|
|
|
|
HelperFormBootstrap::echoConfirmation($this->l('Produits concernés ').'('.count($products_ids).') :<br />'.wordwrap($result, 100, "<br />"));
|
|
|
|
} else {
|
|
|
|
HelperFormBootstrap::echoError($this->l('Veuillez choisir une categorie'));
|
|
|
|
}
|
2016-11-08 14:58:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function display() {
|
|
|
|
global $cookie, $currentIndex;
|
|
|
|
$base_link = $currentIndex . '&token='.Tools::getAdminTokenLite('AdminAntConfigurations');
|
|
|
|
$form = '<style type="text/css">
|
|
|
|
.path_bar {
|
|
|
|
background-color: #F1F1F1;
|
|
|
|
border: 1px solid #565485;
|
|
|
|
}
|
|
|
|
h2 {
|
|
|
|
color: #565485;
|
|
|
|
}
|
|
|
|
fieldset {
|
|
|
|
background: #F1F1F1;
|
|
|
|
border: 1px solid #565485;
|
|
|
|
}
|
|
|
|
legend {
|
|
|
|
background: #565485;
|
|
|
|
background: rgba(86,84,133,0.9);
|
|
|
|
border: 1px solid #565485;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
input[type="text"], input[type="password"],
|
|
|
|
input[type="file"], textarea, select {
|
|
|
|
border: 1px solid #565485;
|
|
|
|
}
|
|
|
|
.button {
|
|
|
|
background-color: rgba(86,84,133,0.7);
|
|
|
|
border: 1px solid #565485;
|
|
|
|
border-left: 1px solid rgba(86,84,133,0.6);
|
|
|
|
border-top: 1px solid rgba(86,84,133,0.6);
|
|
|
|
color: rgba(255,255,255,0.9);
|
|
|
|
padding: 3px;
|
|
|
|
}
|
|
|
|
.button:hover {
|
|
|
|
background-color: #565485;
|
|
|
|
border: 1px solid rgba(86,84,133,0.6);
|
|
|
|
border-left: 1px solid #565485;
|
|
|
|
border-top: 1px solid #565485;
|
|
|
|
color: #fff;
|
|
|
|
padding: 3px;
|
|
|
|
}
|
|
|
|
.button:focus{
|
|
|
|
background-color: rgba(86,84,133,0.6);
|
|
|
|
}
|
|
|
|
</style>';
|
|
|
|
|
|
|
|
$id_sale_options = array();
|
2016-12-26 12:31:43 +01:00
|
|
|
$id_category_options = array();
|
2016-11-08 14:58:29 +01:00
|
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
|
|
SELECT p.`id_sale`, c.`name`, c.`id_category`
|
|
|
|
FROM `'._DB_PREFIX_.'privatesale` p
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON (c.`id_category` = p.`id_category`)
|
|
|
|
WHERE c.`id_lang` = '.$cookie->id_lang.'
|
|
|
|
AND p.`date_start` > "2015-01-01 00:00:00"
|
|
|
|
ORDER BY p.`id_sale` DESC
|
|
|
|
') as $row) {
|
|
|
|
$extrafields = Category::getSalesInfos(array((int) $row['id_category']));
|
|
|
|
$id_sale_options[] = array(
|
|
|
|
'label' => (int) $row['id_sale'].' - '.$row['name'].(empty($extrafields[(int) $row['id_category']]['sales'][1])?'':' - '.$extrafields[(int) $row['id_category']]['sales'][1]) ,
|
|
|
|
'value' => (int) $row['id_sale']
|
|
|
|
);
|
2016-12-26 12:31:43 +01:00
|
|
|
$id_category_options[] = array(
|
|
|
|
'label' => (int) $row['id_sale'].' (#'.(int) $row['id_category'].') - '.$row['name'].(empty($extrafields[(int) $row['id_category']]['sales'][1])?'':' - '.$extrafields[(int) $row['id_category']]['sales'][1]) ,
|
|
|
|
'value' => (int) $row['id_category']
|
|
|
|
);
|
2016-11-08 14:58:29 +01:00
|
|
|
}
|
|
|
|
|
2016-12-12 15:35:45 +01:00
|
|
|
$helperForm = new HelperFormBootstrap();
|
|
|
|
$helperForm->_select2 = true;
|
2016-11-08 14:58:29 +01:00
|
|
|
$helperForm->_forms = array(
|
|
|
|
array(
|
2016-12-12 18:27:45 +01:00
|
|
|
'action' => $base_link,
|
|
|
|
'title' => $this->l('Association Produits'),
|
|
|
|
'icon' => '<span class="glyphicon glyphicon-refresh"></span> ',
|
|
|
|
'class' => 'form-horizontal',
|
|
|
|
'class_div' => 'col-md-3',
|
|
|
|
'information' => 'Permet d\'associer les produits aux ventes lorsque le cron n\'est pas encore passé',
|
|
|
|
'sections' => array(
|
2016-11-08 14:58:29 +01:00
|
|
|
array(
|
2016-12-12 15:35:45 +01:00
|
|
|
'inputs' => array(
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
2016-12-12 18:27:45 +01:00
|
|
|
'class' => 'btn-primary',
|
2016-12-12 15:35:45 +01:00
|
|
|
'name' => 'submitProductSaleCache',
|
|
|
|
'value' => $this->l('Mettre à jour l\'association'),
|
|
|
|
),
|
|
|
|
),
|
2016-11-08 14:58:29 +01:00
|
|
|
),
|
2016-12-12 18:27:45 +01:00
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$helperForm->_forms[] = array(
|
|
|
|
'action' => $base_link,
|
|
|
|
'title' => $this->l('Association categories/ventes'),
|
|
|
|
'icon' => '<span class="glyphicon glyphicon-cog"></span> ',
|
|
|
|
'class' => 'form-horizontal',
|
|
|
|
'class_div' => 'col-md-9',
|
|
|
|
'sections' => array(
|
|
|
|
array(
|
|
|
|
'inputs' => array(
|
|
|
|
array(
|
|
|
|
'type' => 'select2',
|
|
|
|
'class-select' => '',
|
|
|
|
'name' => 'id_sale',
|
|
|
|
'options' => $id_sale_options,
|
2016-12-12 15:35:45 +01:00
|
|
|
),
|
|
|
|
),
|
2016-12-12 18:27:45 +01:00
|
|
|
'actions' => array(
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'class' => 'btn-primary',
|
|
|
|
'name' => 'submitCategorySaleCache',
|
|
|
|
'value' => $this->l('Associer')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'actions-class' => 'text-right',
|
2016-12-12 15:35:45 +01:00
|
|
|
),
|
2016-12-12 18:27:45 +01:00
|
|
|
),
|
2016-11-08 14:58:29 +01:00
|
|
|
);
|
|
|
|
|
2016-12-12 15:35:45 +01:00
|
|
|
if($cookie->id_employee == 1) {
|
2016-12-12 16:23:50 +01:00
|
|
|
$nb_credits = $this->getNbOrderToUpdate();
|
2016-12-13 14:52:58 +01:00
|
|
|
$helperForm->_forms[] = array(
|
|
|
|
'action' => $base_link,
|
|
|
|
'title' => $this->l('Section Antadis'),
|
|
|
|
'class' => 'form-horizontal',
|
|
|
|
'class_div' => 'col-md-12',
|
|
|
|
'sections' => array(
|
|
|
|
array(
|
|
|
|
'class' => 'col-md-6',
|
2016-12-26 12:31:43 +01:00
|
|
|
'title' => $this->l('Actions diverses'),
|
2016-12-13 14:52:58 +01:00
|
|
|
'inputs' => array(
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'class' => 'btn-default',
|
|
|
|
'name' => 'submitUpdateLoyaltyOrders',
|
|
|
|
'label' => $this->l('Credit fidélité ').($nb_credits>0?'('.$nb_credits.')':'').': ',
|
|
|
|
'value' => $this->l('Mettre à jour'),
|
2016-12-12 15:35:45 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2016-12-26 12:31:43 +01:00
|
|
|
array(
|
|
|
|
'class' => 'col-md-6',
|
|
|
|
'title' => $this->l('Mettre à jour PS Cache'),
|
|
|
|
'inputs' => array(
|
|
|
|
array(
|
|
|
|
'label' => $this->l('PS Cache : '),
|
|
|
|
'type' => 'select2',
|
|
|
|
'class-select' => '',
|
|
|
|
'name' => 'id_category',
|
|
|
|
'options' => $id_category_options,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'actions' => array(
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'class' => 'btn-default',
|
|
|
|
'name' => 'submitShowProductCacheSale',
|
|
|
|
'value' => $this->l('Voir'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'class' => 'btn-primary',
|
|
|
|
'name' => 'submitUpdateCacheSale',
|
|
|
|
'value' => $this->l('Ré-Associer'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'actions-class' => 'text-right',
|
|
|
|
),
|
2016-12-13 14:52:58 +01:00
|
|
|
),
|
|
|
|
);
|
2016-12-12 15:35:45 +01:00
|
|
|
}
|
2016-12-13 14:52:58 +01:00
|
|
|
|
|
|
|
$form .= $helperForm->renderStyle();
|
|
|
|
$form .= '<div class="row">'.$helperForm->renderForm(false, NULL, NULL, true).'</div>';
|
|
|
|
$form .= $helperForm->renderScript();
|
2016-12-12 15:35:45 +01:00
|
|
|
|
2016-11-08 14:58:29 +01:00
|
|
|
echo $form;
|
|
|
|
}
|
2016-12-12 15:35:45 +01:00
|
|
|
|
|
|
|
public function updateLoyaltyOrders()
|
|
|
|
{
|
|
|
|
include_once(_PS_ROOT_DIR_.'/modules/loyalty/LoyaltyStateModule.php');
|
|
|
|
include_once(_PS_ROOT_DIR_.'/modules/loyalty/LoyaltyModule.php');
|
|
|
|
$loyaltyStateValidation = new LoyaltyStateModule(LoyaltyStateModule::getValidationId());
|
|
|
|
|
|
|
|
$count_orders = 0;
|
|
|
|
foreach (Db::getInstance()->ExecuteS('
|
|
|
|
SELECT lo.`id_order`, oh.`id_order_state`
|
|
|
|
FROM `'._DB_PREFIX_.'loyalty` lo
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lo.`id_order`)
|
|
|
|
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lo.`id_order` GROUP BY moh.`id_order`)
|
|
|
|
AND oh.`id_order_state` = 4 AND lo.`id_loyalty_state` NOT IN (2,4)
|
|
|
|
') as $order) {
|
|
|
|
if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId((int)$order['id_order'])))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((int)Configuration::get('PS_LOYALTY_NONE_AWARD') AND $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((int)$order['id_order_state'] == $loyaltyStateValidation->id_order_state)
|
|
|
|
{
|
|
|
|
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
|
|
|
|
if ((float)($loyalty->discount_value) == 0) {
|
|
|
|
$loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($loyalty->save()) {
|
|
|
|
$count_orders++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $count_orders;
|
|
|
|
}
|
2016-12-12 16:23:50 +01:00
|
|
|
public function getNbOrderToUpdate(){
|
|
|
|
return Db::getInstance()->getValue('
|
|
|
|
SELECT COUNT(lo.`id_order`)
|
|
|
|
FROM `'._DB_PREFIX_.'loyalty` lo
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lo.`id_order`)
|
|
|
|
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lo.`id_order` GROUP BY moh.`id_order`)
|
|
|
|
AND oh.`id_order_state` = 4 AND lo.`id_loyalty_state` NOT IN (2,4)
|
|
|
|
');
|
|
|
|
}
|
2016-11-08 14:58:29 +01:00
|
|
|
}
|