Bonsoir,
Je souhaite ajouter un fichier .csv contenant le récap d'une commande au mail envoyé par le fichier mailalerts.php
J'ai donc modifié le fichier mailalerts.php en ajoutant le code suivant :
$sqlE = "SELECT o.id_order, SUBSTR(c.email, 1, 5), fm.field_value FROM
ps_orders o, ps_customer c, ps_fmm_custom_userdata fm
WHERE c.id_customer = o.id_customer AND o.id_order = fm.id_order AND o.id_order = ".(int)$order->id;
$orderlist = Db::getInstance()->ExecuteS($sqlE);
$file = fopen(_PS_ROOT_DIR_.'/archives/export.csv', 'w');
$firstline = "E;Num commande;Num Client AD;Commande interne;".$id_order;
$secondline = "L;Ref produit;Nom produit;Quantité;Prix;Date;Message";
fwrite($file, $firstline."\r\n");
fwrite($file, $secondline."\r\n");
// 1ere Boucle d'affichage des informations de la ligne d'entête L
foreach($orderlist AS $orderline){
fwrite($file, "E;");
fwrite($file, implode(';', $orderline)."\r\n");
/****** Sélection des champs pour les secondes lignes *****/
$sqlL = "SELECT DISTINCT od.product_reference as Reference, od.product_name, od.product_quantity, od.product_price, o.date_add, me.message as message_name
FROM
ps_orders o,
ps_customer c,
ps_order_detail od,
ps_product p,
ps_customer_thread th,
ps_customer_message me,
ps_fmm_custom_userdata fm
WHERE
o.id_order = $id_order AND o.id_customer = c.id_customer
AND o.id_order = od.id_order
AND od.product_id = p.id_product
AND o.id_order = th.id_order
AND th.id_customer_thread = me.id_customer_thread
AND o.id_order = fm.id_order
";
$orderlistL = Db::getInstance()->ExecuteS($sqlL);
// 2nd Boucle d'affichage des informations de la ligne d'entête E correspondant à la ligne L
foreach($orderlistL AS $orderlistL){
fwrite($file, "L;");
fwrite($file, implode(';', $orderlistL)."\r\n");
}
}
fclose($file);
$fileAttachment['content'] = file_get_contents(_PS_ROOT_DIR_.'/archives/export.csv'); //File path
$fileAttachment['name'] = 'Export'; //Attachment filename
$fileAttachment['mime'] = 'application/vnd.ms-excel'; //mime file type
if ($dir_mail)
Mail::Send(
$mail_id_lang,
'new_order',
sprintf(Mail::l('Nouvelle commande : #%d - %s', $mail_id_lang), $order->id, $order->reference),
$template_vars,
$merchant_mail,
null,
$configuration['PS_SHOP_EMAIL'],
$configuration['PS_SHOP_NAME'],
$fileAttachment,
null,
$dir_mail,
null,
$id_shop
);
L'envoie du mail et de la pièce jointe fonctionne mais je bloque sur la requette que ne me renvoie rien : je n'arrive pas à lui passer l'id_order dans la clause WHERE... si je force l'id_order en indiquant un chiffre cela fonctionne... c'est certainement un détail mais il ne me saute pas au yeux...