garancia/L4/retour_commande_test_pierre.php

110 lines
3.7 KiB
PHP

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once(dirname(dirname(__FILE__)).'/config/config.inc.php');
$conn = mysql_connect('localhost', 'garanciab_prod', 'yoeLB4Znn1E1');
mysql_select_db('garanciab_prod');
$document_xml = new DomDocument();
$resultat_html = '';
$document_xml->load('OUT/CRPCMD160608223327.xml');
$elements = $document_xml->getElementsByTagName('CRORDERS');
$element = $elements->item(0);
$crorders = $element->childNodes;
foreach ($crorders as $crorder) {
if ($crorder->hasChildNodes() == true) {
$rows = $crorder->childNodes;
$tab_order = array();
$key_colis = 0;
foreach($rows as $row) {
$name_row = $row->nodeName;
if ($name_row == 'CODACTI') {
$tab_order['CODACTI'] = $row->nodeValue;
}
if ($name_row == 'IDORDER') {
$IDORDER = $row->nodeValue;
$id = explode(date('Y'),$IDORDER);
if (count($id) == 1) {
$id = explode(date('Y', strtotime('-1 year') ),$IDORDER);
}
$tab_order['IDORDER'] = $id[0];
}
if ($name_row == 'DATETRT') {
$tab_order['DATETRT'] = $row->nodeValue;
}
if ($name_row == 'ETAPREP') {
$tab_order['ETAPREP'] = $row->nodeValue;
}
if ($name_row == 'COLIS') {
if ($row->hasChildNodes() == true) {
$colis = $row->childNodes;
foreach($colis as $row_colis) {
$name_row_colis = $row_colis->nodeName;
if ($name_row_colis == 'IDCOLIS') {
$tab_order['IDCOLIS'][$key_colis] = $row_colis->nodeValue;
}
}
}
$key_colis++;
}
}
if( strlen($tab_order['IDORDER']) > 5) {
continue;
}
if ($tab_order['ETAPREP'] == "10") {
foreach ($tab_order['IDCOLIS'] as $shipping_number) {
$sql = "update ps_orders set shipping_number = '".$shipping_number."' where id_order = ".(int)$tab_order['IDORDER'];
if ($result = mysql_query($sql, $conn)) {
echo "<br/>Mise a jour effectuee pour la commande tracking #".$tab_order['IDORDER']." : ID COLIS = ".$shipping_number." ( ".$sql.")";
}
$sql = "update ps_order_carrier set tracking_number = '".$shipping_number."' where id_order = ".(int)$tab_order['IDORDER'];
if ($result = mysql_query($sql, $conn)) {
echo "<br/>Mise a jour effectuee pour la commande livraison #".$tab_order['IDORDER']." : ID COLIS = ".$shipping_number." ( ".$sql.")<br/><br/>";
}
}
include_once(dirname(__FILE__) .'/../config/config.inc.php');
$history = new OrderHistory();
$history->id_order = $tab_order['IDORDER'];
$history->id_employee = 7;
$use_existings_payment = false;
$e_order = new Order($tab_order['IDORDER']);
$e_current_order_state=$e_order->current_state;
// commande envoyée
if($e_current_order_state != 4
&& $e_current_order_state != 5
&& $e_current_order_state != 6
&& $e_current_order_state != 7
&& $e_current_order_state != 8)
{
$templateVars = array();
$history->changeIdOrderState2(4, $tab_order['IDORDER'], $use_existings_payment);
$history->addWithemail(true, $templateVars);
}
}
}
}
?>