l('Configurations mises à jour'));
} elseif(Tools::isSubmit('submitProductSaleCache')) {
$fileName = 'cron_sale_cache.php';
$output = shell_exec("ps -ax | grep $fileName | wc -l");
$hour = (int) date('H');
$min = (int) date('i');
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'));
} 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.'
)
');
// 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()
)
');
HelperFormBootstrap::echoConfirmation($this->l('Produits associés aux ventes depuis le produit #').$min_id_product);
} else {
HelperFormBootstrap::echoError($this->l('Pas de produit ajouté depuis 10 jours'));
}
}
} elseif(Tools::isSubmit('submitCategorySaleCache')) {
$id_sale = Tools::getValue('id_sale');
if($id_sale) {
$sale = new Sale((int)$id_sale);
$sale->buildCategoryCache();
// 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()
)
');
HelperFormBootstrap::echoConfirmation($this->l('Categories associés à la vente ').$id_sale);
} else {
HelperFormBootstrap::echoError($this->l('Veuillez choisir une vente'));
}
} elseif(Tools::isSubmit('submitUpdateLoyaltyOrders') && $cookie->id_employee == 1) {
$nb_credits = $this->updateLoyaltyOrders();
HelperFormBootstrap::echoConfirmation($this->l('Credit fidélité mis à jour : ').$nb_credits);
} elseif(
(Tools::isSubmit('submitUpdateCacheSale') || 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'];
}
if(count($products_ids)>0) {
if(Tools::isSubmit('submitShowProductCacheSale')) {
// show product
$result = implode(', ',$products_ids);
HelperFormBootstrap::echoConfirmation($this->l('Produits concernés ').'('.count($products_ids).') :
'.wordwrap($result, 100, "
"));
} elseif(Tools::isSubmit('submitUpdateCacheSale')) {
// update product_ps_cache
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN ('.implode(',',$products_ids).')
');
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('Pas de produits trouvés dans cette catégorie :#').$id_category);
}
} else {
HelperFormBootstrap::echoError($this->l('Veuillez choisir une categorie'));
}
}
}
public function display() {
global $cookie, $currentIndex;
$base_link = $currentIndex . '&token='.Tools::getAdminTokenLite('AdminAntConfigurations');
$form = '';
$id_sale_options = array();
$id_category_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']
);
$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']
);
}
$helperForm = new HelperFormBootstrap();
$helperForm->_select2 = true;
$helperForm->_forms = array(
array(
'action' => $base_link,
'title' => $this->l('Association Produits'),
'icon' => ' ',
'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(
array(
'inputs' => array(
array(
'type' => 'submit',
'class' => 'btn-primary',
'name' => 'submitProductSaleCache',
'value' => $this->l('Mettre à jour l\'association'),
),
),
),
),
)
);
$helperForm->_forms[] = array(
'action' => $base_link,
'title' => $this->l('Association categories/ventes'),
'icon' => ' ',
'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,
),
),
'actions' => array(
array(
'type' => 'submit',
'class' => 'btn-primary',
'name' => 'submitCategorySaleCache',
'value' => $this->l('Associer')
)
),
'actions-class' => 'text-right',
),
),
);
if($cookie->id_employee == 1) {
$nb_credits = $this->getNbOrderToUpdate();
$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',
'title' => $this->l('Actions diverses'),
'inputs' => array(
array(
'type' => 'submit',
'class' => 'btn-default',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'name' => 'submitUpdateLoyaltyOrders',
'label' => $this->l('Credit fidélité ').($nb_credits>0?'('.$nb_credits.')':'').' : ',
'value' => $this->l('Mettre à jour'),
),
array(
'type' => 'simpleText',
'name' => 'carrier_dropshipping',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur Dropshipping :'),
'default' => Configuration::get('ANT_CARRIER_DROP')
),
array(
'type' => 'simpleText',
'name' => 'carrier_domicile',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur domicile :'),
'default' => Configuration::get('ANT_CARRIER_DOM')
),
array(
'type' => 'simpleText',
'name' => 'carriers_socol',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur socol :'),
'default' => Configuration::get('ANT_CARRIERS_SOCOL')
),
array(
'type' => 'simpleText',
'name' => 'carriers_ooh',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur OOH :'),
'default' => Configuration::get('ANT_CARRIERS_OOH')
),
),
),
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',
),
),
'actions' => array(
array(
'type' => 'submit',
'class' => 'btn-primary',
'name' => 'submitUpdateConfigurations',
'value' => $this->l('Mettre à jour les configurations')
)
),
'actions-class' => 'text-center',
);
}
$form .= $helperForm->renderStyle();
$form .= '