cli to send reminder mail

This commit is contained in:
Michael RICOIS 2017-11-29 11:12:32 +01:00
parent eae8fac9ea
commit 580621fc43
7 changed files with 168 additions and 52 deletions

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Message de {shop_name}</title>
<title>Mensaje de {shop_name}</title>
</head>
<body>
<table style="font-family: tahoma,arial,sans-serif; font-size: 12px; color: #000000; width: 550px;">
@ -14,24 +14,22 @@
<td>&nbsp;</td>
</tr>
<tr>
<td align="left">Bonjour <strong>{firstname} {lastname}</strong>,</td>
<td align="left">Buenos d&iacute;as <strong>{firstname} {lastname}</strong>,</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left">
Nous vous informons que vous avez dans votre compte un crédit de fidélité non utilisé suite à votre commande {commandenum}.
Celui-ci expire dans 1 mois.
Venez nous rendre visite sur le site : https://wwww.bebeboutik.com et profiter de nos offres jusqu'à -70% !
Te informamos de que tienes disponible en tu cuenta el crédito de fidelidad generado por tu pedido {commandenum}
<br />Este crédito expira dentro de 1 mes. Conéctate a nuestra web https://www.bebeboutik.es y benefíciate de descuentos de hasta el -70%!
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left">L'équipe Bébé Boutik</td>
<td align="left">Cordialmente,<br /> Servicio al cliente</td>
</tr>
<tr>
<td>&nbsp;</td>

View File

@ -0,0 +1,8 @@
Buenos días {firstname} {lastname},
Te informamos de que tienes disponible en tu cuenta el crédito de fidelidad generado por tu pedido {commandenum}.
Este crédito expira dentro de 1 mes.
Conéctate a nuestra web https://www.bebeboutik.es y benefíciate de descuentos de hasta el -70%!
El equipo Bébé Boutik

View File

@ -1,4 +1,4 @@
Bonjour {firstname} {lastname},
Buenos días {firstname} {lastname},
Acabamos de proceder a reembolsarte tu pedido. Para realizar el pago utilizaste un código de descuento.
Te informamos de que dispones de un nuevo código para que puedas utilizarlo en tu próximo pedido : {voucher_num}.

View File

@ -0,0 +1,45 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Message de {shop_name}</title>
</head>
<body>
<table style="font-family: tahoma,arial,sans-serif; font-size: 12px; color: #000000; width: 550px;">
<tbody>
<tr>
<td align="left"><a title="{shop_name}" href="{shop_url}"><img style="border: none;" src="{shop_logo}" alt="{shop_name}" /></a></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left">Bonjour <strong>{firstname} {lastname}</strong>,</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left">
Nous vous informons que vous avez dans votre compte un crédit de fidélité non utilisé suite à votre commande {commandenum}.
Celui-ci expire dans 1 mois.
Venez nous rendre visite sur le site : https://wwww.bebeboutik.com et profiter de nos offres jusqu'à -70% !
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left">L'équipe Bébé Boutik</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td style="font-size: 12px; border-top: 1px solid #cccccc; padding-top: 5px;" align="center">{shop_name} - <a style="color: #e26ea2;" href="{shop_url}">{shop_url}</a></td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -1,4 +1,4 @@
Bonjour {firstname} {lastname},
Buenos días {firstname} {lastname},
Acabamos de proceder a reembolsarte tu pedido. Para realizar el pago utilizaste un código de descuento.
Te informamos de que dispones de un nuevo código para que puedas utilizarlo en tu próximo pedido : {voucher_num}.

View File

@ -0,0 +1,108 @@
<?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',
'date:'
);
$shortopts = "";
$options = getopt($shortopts, $longopts);
// Options
$optVerbose = false;
if (isset($options['verbose'])) {
$optVerbose = true;
}
$optTest = false;
if (isset($options['dry-run'])) {
$optTest = true;
}
// 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
echo date('YmdHis')." - 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';
$sql = "
SELECT
d.id_discount,
d.id_customer,
d.date_from,
d.date_to,
l.id_order
FROM ps_discount d, ps_loyalty l
WHERE d.active=1 AND d.id_discount=l.id_discount
/*AND d.date_to > '".$dateSqlStart."' AND d.date_to < '".$dateSqlEnd."'*/";
if ($optVerbose) {
echo date('YmdHis')." - START ".$dateSelect->format('Y-m-d')." \n";
}
$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']);
$to = $customerModel->email;
// Order infos
$orderModel = new Order($l['id_order']);
$id_lang = $orderModel->id_lang;
$templateVars = array(
'firstname' => $customerModel->firstname,
'lastname' => $customerModel->lastname,
'commandenum' => $orderModel->id,
);
// Only Display values
if ($optTest) {
print_r($templateVars);
echo "\n";
}
// Send mail
else {
echo date('YmdHis')." - Rappel credit pour le client ".$to;
// @todo : for test
$to = 'ricois@antadis.com';
$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";

View File

@ -1,43 +0,0 @@
<?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',
);
$shortopts = "";
$options = getopt($shortopts, $longopts);
// Liste des crédits fidélites (bons de réduction) valident qui expire dans 1 mois
$sql = "SELECT * FROM ps_discount d WHERE d.active=1";
// ps_loyalty , ps_discount
// ps_loyalty.id_discount != 0
// if (ps_order_discount.id_order) WHEN NO id_order
// ps_discount.date_from
// ps_discount.date_to
// ps_discount.active = 1
// Customer => informations
// Envoi mail
// Créer un template mail FR, ES