createFromFormat('Ymd', $options['date']); } else { $dateSelect->add($delay)->sub(new DateInterval('P1D')); } // Start 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('Y-m-d H:i:s')." - START DATE ".$dateSqlStart." to ".$dateSqlEnd." \n"; } $sql = " SELECT d.id_discount, d.id_customer, d.date_from, d.date_to, l.id_order FROM `"._DB_PREFIX_."discount` d, `"._DB_PREFIX_."loyalty` l LEFT OUTER JOIN `"._DB_PREFIX_."order_discount` od ON (od.id_discount IS NULL) WHERE d.active=1 AND d.`quantity` != 0 AND d.id_discount=l.id_discount AND d.date_to > '".$dateSqlStart."' AND d.date_to < '".$dateSqlEnd."'"; $result = Db::getInstance()->ExecuteS($sql); 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"; } // 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('Y-m-d H:i:s')." - END\n";