bebeboutik/modules/loyalty/bin/reminder.php

119 lines
3.2 KiB
PHP
Raw Normal View History

2017-11-29 11:12:32 +01:00
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_PORT'] = 443;
$_SERVER['HTTP_X_FORWARDED_PORT'] = 443;
$_SERVER['SERVER_PORT'] = 443;
include __DIR__ . '/../../../config/settings.inc.php';
include __DIR__ . '/../../../config/config.inc.php';
if(!Tools::isCli()){
exit();
}
$longopts = array(
'verbose',
'dry-run',
2017-11-30 11:13:11 +01:00
'date:',
'cron',
2017-11-29 11:12:32 +01:00
);
$shortopts = "";
$options = getopt($shortopts, $longopts);
// Options
$optVerbose = false;
if (isset($options['verbose'])) {
$optVerbose = true;
}
$optTest = false;
if (isset($options['dry-run'])) {
$optTest = true;
}
2017-11-30 11:13:11 +01:00
$optCron = false;
if (isset($options['cron'])) {
$optCron = true;
}
2017-11-29 11:12:32 +01:00
// Date
$delay = new DateInterval('P1M');
$dateSelect = new DateTime();
if (isset($options['date'])) {
$dateSelect->createFromFormat('Ymd', $options['date']);
} else {
$dateSelect->add($delay)->sub(new DateInterval('P1D'));
}
// Start
2017-12-06 09:47:15 +01:00
echo date('Y-m-d H:i:s')." - START ".$dateSelect->format('Y-m-d')." \n";
2017-11-29 11:12:32 +01:00
$dateSqlStart = $dateSelect->format('Y-m-d').' 00:00:00';
$dateSqlEnd = $dateSelect->format('Y-m-d').' 23:59:59';
2017-11-30 11:13:11 +01:00
if ($optVerbose) {
2017-12-06 09:47:15 +01:00
echo date('Y-m-d H:i:s')." - START DATE ".$dateSqlStart." to ".$dateSqlEnd." \n";
2017-11-30 11:13:11 +01:00
}
2017-11-29 11:12:32 +01:00
$sql = "
SELECT
d.id_discount,
d.id_customer,
d.date_from,
d.date_to,
l.id_order
2017-12-06 09:56:49 +01:00
FROM `"._DB_PREFIX_."discount` d, `"._DB_PREFIX_."loyalty` l
2017-12-06 09:47:15 +01:00
LEFT OUTER JOIN `"._DB_PREFIX_."order_discount` od ON (od.id_discount IS NULL)
2018-01-30 17:47:03 +01:00
WHERE d.active=1 AND d.`quantity` != 0 AND d.id_discount=l.id_discount
2017-11-29 14:40:23 +01:00
AND d.date_to > '".$dateSqlStart."' AND d.date_to < '".$dateSqlEnd."'";
2017-11-29 11:12:32 +01:00
$result = Db::getInstance()->ExecuteS($sql);
2017-12-06 09:47:15 +01:00
if ($result === false) {
echo $sql;
echo "\n";
} else {
$nb = count($result);
if ($optVerbose) { echo date('YmdHis')." - $nb mails to send \n"; }
if ($nb > 0) {
foreach($result as $l) {
// Customer infos
$customerModel = new Customer($l['id_customer']);
// Order infos
$orderModel = new Order($l['id_order']);
$id_lang = $orderModel->id_lang;
$templateVars = array(
'{firstname}' => $customerModel->firstname,
'{lastname}' => $customerModel->lastname,
'{commandenum}' => $orderModel->id,
);
echo date('Y-m-d H:i:s')." - Rappel credit pour le client ".$customerModel->email;
$to = $customerModel->email;
// Only Display values
if ($optTest) {
print_r($templateVars);
echo "\n";
2017-11-29 11:12:32 +01:00
}
2017-12-06 09:47:15 +01:00
// Send mail
2017-11-29 11:12:32 +01:00
else {
2017-12-06 09:47:15 +01:00
$isSent = Mail::Send($id_lang, 'loyalty_discount_reminder',
Mail::l('Your loyalty credits', $id_lang), $templateVars, $to,
$customerModel->firstname.' '.$customerModel->lastname);
if ($isSent) {
echo " - Envoyé";
}
else {
echo " - ERROR";
}
2017-11-29 11:12:32 +01:00
}
2017-12-06 09:47:15 +01:00
echo "\n";
2017-11-29 11:12:32 +01:00
}
}
}
2017-12-06 09:47:15 +01:00
echo date('Y-m-d H:i:s')." - END\n";