bebeboutik/modules/philea_magistor/cron_auto_sync.php

52 lines
1.3 KiB
PHP
Raw Normal View History

<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../config/config.inc.php';
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
set_time_limit(600);
$auto_sync_sales = Db::getInstance()->executeS('
SELECT DISTINCT pmas.`id_sale`
2016-11-03 11:58:23 +01:00
FROM `'._DB_PREFIX_.'philea_auto_sync` pmas
LEFT JOIN `'._DB_PREFIX_.'philea_sync` pms
ON pms.`id_sale` = pmas.`id_sale`
LEFT JOIN `'._DB_PREFIX_.'privatesale` p
ON p.`id_sale` = pmas.`id_sale`
WHERE pms.`status` >= 2
AND pmas.active = 1
AND p.date_start <= NOW()
AND p.date_end >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
');
if ($auto_sync_sales && count($auto_sync_sales))
{
foreach ($auto_sync_sales as $sale) {
$id_sale = (int) $sale['id_sale'];
if (Db::getInstance()->getValue('
SELECT COUNT(*)
2016-11-03 11:58:23 +01:00
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `id_sale` = ' . (int) $id_sale . '
AND `status` = 3
')){
continue;
}
Db::getInstance()->execute('
2016-11-03 11:58:23 +01:00
INSERT INTO `'._DB_PREFIX_.'philea_sync`
VALUES (
DEFAULT,
'.(int) $id_sale.',
3,
NOW()
)
');
$sql = '
2016-11-03 11:58:23 +01:00
UPDATE `'._DB_PREFIX_.'philea_auto_sync`
SET `last_sent` = NOW()
WHERE `id_sale` = ' . (int) $id_sale . '
LIMIT 1';
Db::getInstance()->execute($sql);
2016-11-03 11:58:23 +01:00
system('cd '.dirname(__FILE__).'/script && php send_commande.php '.(int) $id_sale);
sleep(10);
}
}