2016-11-08 14:58:29 +01:00
|
|
|
<?php
|
|
|
|
if(!defined('_PS_VERSION_')) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
|
|
|
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");
|
|
|
|
if($output > 2){
|
|
|
|
echo '<p class="error">'.$this->l('Association automatique en cours, réessayez plus tard').'</p><br />';
|
|
|
|
}
|
2016-11-08 14:58:29 +01:00
|
|
|
$hour = (int) date('H');
|
|
|
|
$min = (int) date('i');
|
|
|
|
if ($hour%3 == 0 && $min <= 20 && $min >= 10 ){
|
|
|
|
echo '<p class="error">'.$this->l('Association automatique en cours, réessayez plus tard').'</p><br />';
|
|
|
|
} 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-11-08 14:58:29 +01:00
|
|
|
echo '<p class="conf">'.$this->l('Produits associés aux ventes depuis le produit #').$min_id_product.'</p><br />';
|
|
|
|
} else {
|
|
|
|
echo '<p class="error">'.$this->l('Pas de produit ajouté depuis 10 jours').'</p><br />';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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-11-08 14:58:29 +01:00
|
|
|
echo '<p class="conf">'.$this->l('Categories associés à la vente ').$id_sale.'</p><br />';
|
|
|
|
} else {
|
|
|
|
echo '<p class="error">'.$this->l('Veuillez choisir une vente').'</p><br />';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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>';
|
|
|
|
|
|
|
|
$helperForm = new HelperForm();
|
|
|
|
$helperForm->_forms = array(
|
|
|
|
array(
|
|
|
|
'action' => $base_link,
|
|
|
|
'legend' => $this->l('Association Vente - Produits'),
|
|
|
|
'actions' => array(
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'submitProductSaleCache',
|
|
|
|
'label' => $this->l('Associer les produits aux ventes')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$form .= $helperForm->renderForm(false, NULL, NULL, true);
|
|
|
|
|
|
|
|
$id_sale_options = array();
|
|
|
|
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']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$helperForm = new HelperForm();
|
|
|
|
$helperForm->_forms = array(
|
|
|
|
array(
|
|
|
|
'action' => $base_link,
|
|
|
|
'legend' => $this->l('Association Vente - Categories'),
|
|
|
|
'inputs' => array(
|
|
|
|
array(
|
|
|
|
'type' => 'select-styled',
|
|
|
|
'class-select' => 'bg-purple-light big-select',
|
|
|
|
'name' => 'id_sale',
|
|
|
|
'label' => $this->l('Select a sale'),
|
|
|
|
'options' => $id_sale_options,
|
|
|
|
'filter' => true,
|
|
|
|
'filter_text' => $this->l('Filter par vente')
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'actions' => array(
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'submitCategorySaleCache',
|
|
|
|
'label' => $this->l('Associer les categories aux ventes')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$form .= $helperForm->renderForm(false, NULL, NULL, true);
|
|
|
|
echo $form;
|
|
|
|
}
|
|
|
|
}
|