From 62b7f44ed5a443abcb71936c2d2200e969a4dc3c Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Wed, 6 Dec 2017 09:47:15 +0100 Subject: [PATCH] Fix sql --- modules/loyalty/bin/reminder.php | 93 +++++++++++++++++--------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/modules/loyalty/bin/reminder.php b/modules/loyalty/bin/reminder.php index 4da81e16..6dde144b 100644 --- a/modules/loyalty/bin/reminder.php +++ b/modules/loyalty/bin/reminder.php @@ -48,13 +48,13 @@ if (isset($options['date'])) { } // Start -echo date('YmdHis')." - START ".$dateSelect->format('Y-m-d')." \n"; +echo date('Y-m-d H:i:s')." - START ".$dateSelect->format('Y-m-d')." \n"; $dateSqlStart = $dateSelect->format('Y-m-d').' 00:00:00'; $dateSqlEnd = $dateSelect->format('Y-m-d').' 23:59:59'; if ($optVerbose) { - echo date('YmdHis')." - START DATE ".$dateSqlStart." to ".$dateSqlEnd." \n"; + echo date('Y-m-d H:i:s')." - START DATE ".$dateSqlStart." to ".$dateSqlEnd." \n"; } $sql = " @@ -65,53 +65,58 @@ SELECT d.date_to, l.id_order FROM `"._DB_PREFIX_."discount` d, "._DB_PREFIX_."loyalty l, "._DB_PREFIX_."order_discount -LEFT OUTER JOIN `"._DB_PREFIX_."order_discount od ON (od.id_discount IS NULL) +LEFT OUTER JOIN `"._DB_PREFIX_."order_discount` od ON (od.id_discount IS NULL) WHERE d.active=1 AND d.id_discount=l.id_discount AND d.date_to > '".$dateSqlStart."' AND d.date_to < '".$dateSqlEnd."'"; $result = Db::getInstance()->ExecuteS($sql); -$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('YmdHis')." - Rappel credit pour le client ".$customerModel->email; - - $to = $customerModel->email; - // @todo : for test - $to = 'ricois@antadis.com'; - - // Only Display values - if ($optTest) { - print_r($templateVars); +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; + // @todo : for test + $to = 'ricois@antadis.com'; + + // Only Display values + if ($optTest) { + print_r($templateVars); + echo "\n"; + } + // Send mail + else { + $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"; + } + + } echo "\n"; } - // Send mail - else { - $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"; - } - - } - echo "\n"; } } -echo date('YmdHis')." - END\n"; +echo date('Y-m-d H:i:s')." - END\n";