1649 lines
52 KiB
PHP
Executable File
1649 lines
52 KiB
PHP
Executable File
<?php
|
|
if (!defined('_CAN_LOAD_FILES_'))
|
|
exit;
|
|
|
|
class neolys extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'neolys';
|
|
$this->version = '1.0';
|
|
$this->author = 'Neolys IT';
|
|
$this->tab = 'shipping_logistics';
|
|
$this->module_key = '860c602ea93e26697a23dfe497d32433';
|
|
|
|
$this->_postErrors = array();
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Neolys - Partenaire Logistique');
|
|
$this->description = $this->l('Interface PS v1.6 avec Neolys');
|
|
}
|
|
|
|
protected function setConfig($key, $value)
|
|
{
|
|
return Configuration::updateValue($this->name.$key,$value,true);
|
|
}
|
|
|
|
protected function getConfig($value)
|
|
{
|
|
return Configuration::get($this->name.$value);
|
|
}
|
|
|
|
protected function deleteConfig($value)
|
|
{
|
|
return Configuration::deleteByName($this->name.$value);
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (!parent::install()
|
|
// OR !$this->registerHook('')
|
|
OR !$this->setConfig("WS_KEY","")
|
|
OR !$this->setConfig("FTP_IP","")
|
|
OR !$this->setConfig("FTP_login","")
|
|
OR !$this->setConfig("FTP_password","")
|
|
|
|
OR !$this->setConfig("order_flag","")
|
|
OR !$this->setConfig("order_directory","")
|
|
|
|
OR !$this->setConfig("article_flag","")
|
|
OR !$this->setConfig("article_directory","")
|
|
|
|
OR !$this->setConfig("statuts_flag","")
|
|
|
|
OR !$this->setConfig("stock_flag","")
|
|
OR !$this->setConfig("stock_directory","")
|
|
|
|
|
|
)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
$this->deleteConfig("WS_KEY");
|
|
$this->deleteConfig("FTP_IP");
|
|
$this->deleteConfig("FTP_login");
|
|
$this->deleteConfig("FTP_password");
|
|
$this->deleteConfig("order_flag");
|
|
$this->deleteConfig("order_directory");
|
|
$this->deleteConfig("article_flag");
|
|
$this->deleteConfig("article_directory");
|
|
$this->deleteConfig("statuts_flag");
|
|
$this->deleteConfig("stock_flag");
|
|
$this->deleteConfig("stock_directory");
|
|
|
|
parent::uninstall();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//public function hook($params)
|
|
// {
|
|
|
|
// }
|
|
|
|
|
|
private function _postProcess()
|
|
{
|
|
|
|
$this->setConfig("WS_KEY", Tools::getValue("WS_KEY"));
|
|
|
|
$this->setConfig("FTP_IP", Tools::getValue("FTP_IP"));
|
|
|
|
$this->setConfig("FTP_login", Tools::getValue("FTP_login"));
|
|
|
|
$this->setConfig("FTP_password", Tools::getValue("FTP_password"));
|
|
|
|
$this->setConfig("order_flag", Tools::getValue("order_flag"));
|
|
$this->setConfig("order_directory", './ecom_to_neolys/ordres/received/');
|
|
|
|
$this->setConfig("article_flag", Tools::getValue("article_flag"));
|
|
$this->setConfig("article_directory", './ecom_to_neolys/articles/received/');
|
|
|
|
$this->setConfig("statuts_flag", Tools::getValue("statuts_flag"));
|
|
|
|
$this->setConfig("stock_flag", Tools::getValue("stock_flag"));
|
|
$this->setConfig("stock_directory", './neolys_to_ecom/stock/');
|
|
|
|
if(Tools::getValue("force_articles")== 'YES')
|
|
{$cart = new neolys;
|
|
$cart->getContentArticles();
|
|
}
|
|
if(Tools::getValue("force_orders")== 'YES')
|
|
{$cart = new neolys;
|
|
$cart->getContentCommandes();
|
|
}
|
|
if(Tools::getValue("force_stock")== 'YES')
|
|
{$cart = new neolys;
|
|
$cart->updateStock();
|
|
}
|
|
if(Tools::getValue("force_statuts")== 'YES')
|
|
{$cart = new neolys;
|
|
$cart->updateStatuts();
|
|
}
|
|
|
|
Tools::redirectAdmin('?tab=AdminModules&configure=neolys&token='.Tools::getValue('token'));
|
|
|
|
|
|
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
|
|
$this->_html .= "<h2>".$this->displayName."</h2>";
|
|
|
|
if (Tools::isSubmit("submit"))
|
|
{
|
|
$this->_postProcess();
|
|
|
|
}
|
|
|
|
$this->_displayForm();
|
|
|
|
return $this->_html;
|
|
}
|
|
|
|
private function _displayForm()
|
|
{
|
|
|
|
$this->_html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
|
|
|
|
<fieldset>
|
|
<legend><img src="../modules/neolys/logo.gif" alt="" class="middle" />'.$this->l('Connexion Neolys').'</legend>
|
|
|
|
<label>'.$this->l("Webservice Key").'</label>
|
|
<div class="margin-form">
|
|
<input type="text" name="WS_KEY" value="'.$this->getConfig("WS_KEY").'" />
|
|
</div>
|
|
|
|
<label>'.$this->l("IP").'</label>
|
|
<div class="margin-form">
|
|
<input type="text" name="FTP_IP" value="'.$this->getConfig("FTP_IP").'" />
|
|
</div>
|
|
|
|
<label>'.$this->l("Login").'</label>
|
|
<div class="margin-form">
|
|
<input type="text" name="FTP_login" value="'.$this->getConfig("FTP_login").'" />
|
|
</div>
|
|
|
|
<label>'.$this->l("Mot de passe").'</label>
|
|
<div class="margin-form">
|
|
<input type="password" name="FTP_password" value="'.$this->getConfig("FTP_password").'" />
|
|
</div>
|
|
</fieldset>';
|
|
|
|
$this->_html .= '<br>';
|
|
|
|
$this->_html .= '<fieldset>
|
|
<legend><img src="../modules/neolys/logo.gif" alt="" class="middle" />'.$this->l('Envoi des Commandes').'</legend>
|
|
|
|
<label>'.$this->l("Envoi : ").'</label>
|
|
<div class="margin-form">';
|
|
if( $this->getConfig("order_flag") == 1 )
|
|
{$this->_html .= '<img src="../img/admin/enabled.gif" />
|
|
<input type="radio" name="order_flag" id="active_on" value="1" CHECKED />';
|
|
$this->_html .= '
|
|
Activé
|
|
<br> ';
|
|
$this->_html .= '<img src="../img/admin/disabled.gif" />
|
|
<input type="radio" name="order_flag" id="active_off" value="0" />';
|
|
$this->_html .= '
|
|
Désactivé
|
|
';
|
|
}
|
|
else
|
|
{$this->_html .= '<img src="../img/admin/enabled.gif" />
|
|
<input type="radio" name="order_flag" id="active_on" value="1" />';
|
|
$this->_html .= '
|
|
Activé
|
|
<br> ';
|
|
$this->_html .= '<img src="../img/admin/disabled.gif" />
|
|
<input type="radio" name="order_flag" id="active_off" value="0" CHECKED />';
|
|
$this->_html .= '
|
|
Désactivé
|
|
';
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->_html .= '</div>
|
|
|
|
<br>
|
|
|
|
<label>'.$this->l("Repertoire distant : ").'</label>
|
|
<div class="margin-form">
|
|
'.$this->getConfig("order_directory").'
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<label>'.$this->l("Executer un envoi : ").'</label>
|
|
<div class="margin-form">
|
|
<input type="checkbox" name="force_orders" value="YES">
|
|
</div>
|
|
|
|
</fieldset> ';
|
|
|
|
$this->_html .= '<br>';
|
|
|
|
$this->_html .= '<fieldset>
|
|
<legend><img src="../modules/neolys/logo.gif" alt="" class="middle" />'.$this->l('Envoi de la base article').'</legend>
|
|
|
|
<label>'.$this->l("Envoi : ").'</label>
|
|
<div class="margin-form">';
|
|
if( $this->getConfig("article_flag") == 1 )
|
|
{$this->_html .= '<img src="../img/admin/enabled.gif" />
|
|
<input type="radio" name="article_flag" id="active_on" value="1" CHECKED />';
|
|
$this->_html .= '
|
|
Activé
|
|
<br> ';
|
|
$this->_html .= '<img src="../img/admin/disabled.gif" />
|
|
<input type="radio" name="article_flag" id="active_off" value="0" />';
|
|
$this->_html .= '
|
|
Désactivé
|
|
';
|
|
}
|
|
else
|
|
{$this->_html .= '<img src="../img/admin/enabled.gif" />
|
|
<input type="radio" name="article_flag" id="active_on" value="1" />';
|
|
$this->_html .= '
|
|
Activé
|
|
<br> ';
|
|
$this->_html .= '<img src="../img/admin/disabled.gif" />
|
|
<input type="radio" name="article_flag" id="active_off" value="0" CHECKED />';
|
|
$this->_html .= '
|
|
Désactivé
|
|
';
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->_html .= '</div>
|
|
|
|
<br>
|
|
|
|
<label>'.$this->l("Repertoire distant : ").'</label>
|
|
<div class="margin-form">
|
|
'.$this->getConfig("article_directory").'
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<label>'.$this->l("Executer un envoi : ").'</label>
|
|
<div class="margin-form">
|
|
<input type="checkbox" name="force_articles" value="YES">
|
|
</div>
|
|
|
|
</fieldset> ';
|
|
|
|
$this->_html .= '<br>';
|
|
|
|
|
|
|
|
$this->_html .= '<fieldset>
|
|
|
|
<legend><img src="../modules/neolys/logo.gif" alt="" class="middle" />'.$this->l('Mise à jour du stock').'</legend>
|
|
|
|
<label>'.$this->l("Mise a jour : ").'</label>
|
|
<div class="margin-form">';
|
|
if( $this->getConfig("stock_flag") == 1 )
|
|
{$this->_html .= '<img src="../img/admin/enabled.gif" />
|
|
<input type="radio" name="stock_flag" id="active_on" value="1" CHECKED />';
|
|
$this->_html .= '
|
|
Activé
|
|
<br> ';
|
|
$this->_html .= '<img src="../img/admin/disabled.gif" />
|
|
<input type="radio" name="stock_flag" id="active_off" value="0" />';
|
|
$this->_html .= '
|
|
Désactivé
|
|
';
|
|
}
|
|
else
|
|
{$this->_html .= '<img src="../img/admin/enabled.gif" />
|
|
<input type="radio" name="stock_flag" id="active_on" value="1" />';
|
|
$this->_html .= '
|
|
Activé
|
|
<br> ';
|
|
$this->_html .= '<img src="../img/admin/disabled.gif" />
|
|
<input type="radio" name="stock_flag" id="active_off" value="0" CHECKED />';
|
|
$this->_html .= '
|
|
Désactivé
|
|
';
|
|
}
|
|
|
|
$this->_html .= '</div>
|
|
|
|
<br>
|
|
|
|
<label>'.$this->l("Repertoire distant : ").'</label>
|
|
<div class="margin-form">
|
|
'.$this->getConfig("stock_directory").'
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<label>'.$this->l("Executer une MAJ : ").'</label>
|
|
<div class="margin-form">
|
|
<input type="checkbox" name="force_stock" value="YES">
|
|
</div>
|
|
|
|
</fieldset>';
|
|
|
|
$this->_html .= '<br>';
|
|
|
|
$this->_html .= '<fieldset>
|
|
|
|
<legend><img src="../modules/neolys/logo.gif" alt="" class="middle" />'.$this->l('Mise à jour des statuts des commandes').'</legend>
|
|
|
|
<label>'.$this->l("Mise a jour : ").'</label>
|
|
<div class="margin-form">';
|
|
if( $this->getConfig("statuts_flag") == 1 )
|
|
{$this->_html .= '<img src="../img/admin/enabled.gif" />
|
|
<input type="radio" name="statuts_flag" id="active_on" value="1" CHECKED />';
|
|
$this->_html .= '
|
|
Activé
|
|
<br> ';
|
|
$this->_html .= '<img src="../img/admin/disabled.gif" />
|
|
<input type="radio" name="statuts_flag" id="active_off" value="0" />';
|
|
$this->_html .= '
|
|
Désactivé
|
|
';
|
|
}
|
|
else
|
|
{$this->_html .= '<img src="../img/admin/enabled.gif" />
|
|
<input type="radio" name="statuts_flag" id="active_on" value="1" />';
|
|
$this->_html .= '
|
|
Activé
|
|
<br> ';
|
|
$this->_html .= '<img src="../img/admin/disabled.gif" />
|
|
<input type="radio" name="statuts_flag" id="active_off" value="0" CHECKED />';
|
|
$this->_html .= '
|
|
Désactivé
|
|
';
|
|
}
|
|
|
|
$this->_html .= '</div>
|
|
<br>
|
|
|
|
<label>'.$this->l("Executer une MAJ : ").'</label>
|
|
<div class="margin-form">
|
|
<input type="checkbox" name="force_statuts" value="YES">
|
|
</div>';
|
|
|
|
|
|
$this->_html .= '</div>
|
|
|
|
<br>
|
|
|
|
</fieldset>';
|
|
|
|
|
|
|
|
$this->_html .= '<br>
|
|
<fieldset>
|
|
<br />
|
|
<center><input type="submit" name="submit" value="'.$this->l('Enregistrer').'" class="button" /></center>
|
|
</fieldset>
|
|
</form>';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getcategoryname($id_category)
|
|
{
|
|
$id_lang = $this->getidLang4Neolys() ;
|
|
|
|
$sql_category = "select cl.name AS name, cl.description AS descr
|
|
from "._DB_PREFIX_."category_lang cl
|
|
where cl.id_category = '$id_category' and cl.id_lang = '$id_lang'";
|
|
//and cl.link_rewrite <> 'home' ";
|
|
|
|
$row_category = Db::getInstance()->getRow($sql_category);
|
|
|
|
$value = $row_category['name'];
|
|
|
|
return($value);
|
|
}
|
|
|
|
public function getrootcategory($id_category)
|
|
{
|
|
|
|
$root_level = 1 ;
|
|
|
|
$sql_category = "select level_depth , id_parent from "._DB_PREFIX_."category where id_category = '$id_category' ";
|
|
$row_category = Db::getInstance()->getRow($sql_category);
|
|
$level_depth = $row_category['level_depth'];
|
|
$id_father = $row_category['id_parent'];
|
|
|
|
if($level_depth == $root_level){$root_category = $id_category ;}
|
|
|
|
if($level_depth > $root_level)
|
|
{
|
|
for($i=$level_depth;$i>1;$i--)
|
|
{
|
|
$sql_category_2 = "select level_depth , id_parent from "._DB_PREFIX_."category where id_category = '$id_father' ";
|
|
|
|
$row_category_2 = Db::getInstance()->getRow($sql_category_2);
|
|
$level_depth_2 = $row_category_2['level_depth'];
|
|
|
|
if($level_depth_2 == $root_level){$root_category = $id_father ;}
|
|
|
|
$id_father = $row_category_2['id_parent'];
|
|
|
|
}
|
|
|
|
}
|
|
return($root_category);
|
|
}
|
|
|
|
public function getcategoriesproduct($id_product)
|
|
{
|
|
$stack = array();
|
|
|
|
$id_lang = $this->getidLang4Neolys() ;
|
|
|
|
$sql_categories = "select cl.name AS name, cl.description AS descr from "._DB_PREFIX_."category_product cp , "._DB_PREFIX_."category_lang cl
|
|
where cp.id_product = '$id_product' and cp.id_category = cl.id_category and cl.id_lang = '$id_lang'
|
|
and cl.link_rewrite <> 'home' ";
|
|
|
|
$LIST_CATEGORIES = Db::getInstance()->Query($sql_categories);
|
|
while($category = Db::getInstance()->nextRow($LIST_CATEGORIES))
|
|
{
|
|
$c_name = $category['name'];
|
|
|
|
array_push($stack,$c_name);
|
|
|
|
}
|
|
return($stack);
|
|
}
|
|
|
|
|
|
public function getgroupattributename($id_attribute, $id_lang)
|
|
{
|
|
$sql = "SELECT pagl.public_name AS PUBLIC_NAME
|
|
FROM "._DB_PREFIX_."attribute pa , "._DB_PREFIX_."attribute_group_lang pagl
|
|
where pagl.id_lang = '$id_lang'
|
|
and pa.id_attribute_group = pagl.id_attribute_group
|
|
and pa.id_attribute = '$id_attribute'
|
|
";
|
|
$row_attr_group = Db::getInstance()->getRow($sql);
|
|
|
|
$value = $row_attr_group['PUBLIC_NAME'];
|
|
|
|
return($value);
|
|
}
|
|
|
|
public function getidLang4Neolys()
|
|
{
|
|
$sql = "SELECT "._DB_PREFIX_."lang.id_lang FROM "._DB_PREFIX_."lang where iso_code = 'fr' ";
|
|
$row_lang = Db::getInstance()->getRow($sql);
|
|
|
|
$id_lang = $row_lang['id_lang'];
|
|
|
|
return($id_lang);
|
|
}
|
|
|
|
public function getordermessages($id_order, $id_customer)
|
|
{
|
|
$stack = array();
|
|
$sql_mes = "select * from "._DB_PREFIX_."message where id_order = '$id_order' and private ='0' and id_customer = '$id_customer' ";
|
|
|
|
$list_mes = Db::getInstance()->Query($sql_mes);
|
|
|
|
while($messages = Db::getInstance()->nextRow($list_mes))
|
|
{
|
|
|
|
$message = $messages['message'] ;
|
|
|
|
array_push($stack,$message);
|
|
|
|
}
|
|
|
|
return($stack);
|
|
}
|
|
|
|
public function getshippingdetails($id_cart)
|
|
{
|
|
|
|
$stack = array();
|
|
|
|
$sql_so = "select * from "._DB_PREFIX_."socolissimo_delivery_info where id_cart = '$id_cart' ";
|
|
|
|
$details_so = Db::getInstance()->Execute($sql_so);
|
|
$lines_so = Db::getInstance()->numRows($details_so);
|
|
|
|
if ($lines_so > 0)
|
|
{
|
|
array_push($stack,'SOCOL');
|
|
$row_so = Db::getInstance()->getRow($sql_so);
|
|
$data1 = $row_so['delivery_mode'];
|
|
array_push($stack,$data1);
|
|
$data2 = $row_so['prid'];
|
|
array_push($stack,$data2);
|
|
$data3 = $row_so['cephonenumber'];
|
|
array_push($stack,$data3);
|
|
$data4 = $row_so['ceemail'];
|
|
array_push($stack,$data4);
|
|
$data5 = $row_so['cecompanyname'];
|
|
array_push($stack,$data5);
|
|
$data6 = $row_so['cedeliveryinformation'];
|
|
array_push($stack,$data6);
|
|
$data7 = $row_so['cedoorcode1'];
|
|
array_push($stack,$data7);
|
|
$data8 = $row_so['cedoorcode2'];
|
|
array_push($stack,$data8);
|
|
$data9 = $row_so['prname'];
|
|
array_push($stack,$data9);
|
|
$data10 = $row_so['prfirstname'];
|
|
array_push($stack,$data10);
|
|
$data11 = $row_so['przipcode'];
|
|
array_push($stack,$data11);
|
|
$data12 = $row_so['prtown'];
|
|
array_push($stack,$data12);
|
|
}
|
|
|
|
$sql_mr = "select * from "._DB_PREFIX_."mr_selected where id_cart = '$id_cart' ";
|
|
|
|
$details_mr = Db::getInstance()->Execute($sql_mr);
|
|
$lines_mr = Db::getInstance()->numRows($details_mr);
|
|
|
|
if ($lines_mr > 0)
|
|
{
|
|
array_push($stack,'MR');
|
|
$row_mr = Db::getInstance()->getRow($sql_mr);
|
|
$data1 = '';
|
|
array_push($stack,$data1);
|
|
$data2 = $row_mr['MR_Selected_Num'];
|
|
array_push($stack,$data2);
|
|
$data3 = '';
|
|
array_push($stack,$data3);
|
|
$data4 = '';
|
|
array_push($stack,$data4);
|
|
$data5 = '';
|
|
array_push($stack,$data5);
|
|
$data6 = '';
|
|
array_push($stack,$data6);
|
|
$data7 = '';
|
|
array_push($stack,$data7);
|
|
$data8 = '';
|
|
array_push($stack,$data8);
|
|
}
|
|
|
|
return($stack);
|
|
}
|
|
|
|
|
|
public function getContentArticles()
|
|
{
|
|
|
|
if($this->getConfig("article_flag")=='1')
|
|
{
|
|
$id_lang = $this->getidLang4Neolys() ;
|
|
|
|
//$URL_SITE = "http://" . Configuration::get('CANONICAL_URL') ;
|
|
|
|
$DATE_LOG = date("Ymd H:i:s");
|
|
$log_articles = "Neolys Articles | ".$DATE_LOG." | ";
|
|
|
|
$DATE = date("YmdHis");
|
|
$FICHIER = "base_articles_". $DATE .".xml";
|
|
|
|
$PATH = dirname(__FILE__) . "/data/" ;
|
|
|
|
$FICHIER_A_ENVOYER = $PATH . $FICHIER ;
|
|
|
|
$f = fopen($FICHIER_A_ENVOYER,"w");
|
|
|
|
//DEBUT DU FICHIER
|
|
// antadis 12667 -encoding change
|
|
$entetxml = '<?xml version="1.0" encoding="UTF-8" ?>' ;
|
|
$entetxml .= "\n" ;
|
|
$entetxml .= '<references version="'.$this->version.'">' ;
|
|
$entetxml .= "\n" ;
|
|
fputs($f,$entetxml);
|
|
|
|
|
|
$SQL_PRODUITS = 'SELECT
|
|
'._DB_PREFIX_.'product.id_product ,
|
|
'._DB_PREFIX_.'product.active as PRODUCT_ACTIVE,
|
|
'._DB_PREFIX_.'product.reference ,
|
|
'._DB_PREFIX_.'product.supplier_reference ,
|
|
'._DB_PREFIX_.'product.ean13 ,
|
|
'._DB_PREFIX_.'product.weight ,
|
|
'._DB_PREFIX_.'product_lang.link_rewrite ,
|
|
'._DB_PREFIX_.'product.quantity ,
|
|
'._DB_PREFIX_.'supplier.name as namefournisseur,
|
|
'._DB_PREFIX_.'product.is_virtual as virtuel,
|
|
'._DB_PREFIX_.'product_lang.name as nameproduct ,
|
|
'._DB_PREFIX_.'product.id_category_default as id_cat_default,
|
|
'._DB_PREFIX_.'product_lang.link_rewrite
|
|
FROM '._DB_PREFIX_.'product
|
|
LEFT JOIN '._DB_PREFIX_.'product_lang ON '._DB_PREFIX_.'product_lang.id_product = '._DB_PREFIX_.'product.id_product
|
|
LEFT JOIN '._DB_PREFIX_.'supplier ON '._DB_PREFIX_.'supplier.id_supplier = '._DB_PREFIX_.'product.id_supplier
|
|
WHERE
|
|
'._DB_PREFIX_.'product_lang.id_lang = '.$id_lang.'
|
|
group by '._DB_PREFIX_.'product.id_product ';
|
|
|
|
|
|
$LIST_PRODUITS = Db::getInstance()->Query($SQL_PRODUITS);
|
|
|
|
$NOMBRELIGNE_PRODUITS = Db::getInstance()->numRows($LIST_PRODUITS);
|
|
|
|
|
|
$articlesxml = "<articles count=\"" .$NOMBRELIGNE_PRODUITS. "\">\n" ;
|
|
|
|
fputs($f,$articlesxml);
|
|
|
|
while($produit = Db::getInstance()->nextRow($LIST_PRODUITS))
|
|
{
|
|
$id_product = $produit['id_product'] ;
|
|
|
|
$SQL_IMAGE = 'SELECT '._DB_PREFIX_.'image.id_image
|
|
FROM '._DB_PREFIX_.'image where '._DB_PREFIX_.'image.id_product = '.$produit['id_product'].' order by '._DB_PREFIX_.'image.cover desc';
|
|
//$LIST_IMAGES = Db::getInstance()->Query($SQL_IMAGE);
|
|
|
|
//echo $SQL_IMAGE . "\n" ;
|
|
|
|
$row_id_image = Db::getInstance()->getRow($SQL_IMAGE);
|
|
|
|
$id_image = $row_id_image['id_image'];
|
|
|
|
if($id_image == '')
|
|
{
|
|
$url = '';
|
|
}
|
|
else
|
|
{
|
|
|
|
$url = Link::getImageLink($produit['link_rewrite'], $produit['id_product'].'-'.$id_image, 'home');
|
|
|
|
}
|
|
|
|
$default_category = $produit['id_cat_default'] ;
|
|
|
|
$debutproduitxml = "\n\n<line>\n" ;
|
|
$debutproduitxml .= "<ref><![CDATA[". $produit['id_product'] . "]]></ref>\n" ;
|
|
$debutproduitxml .= "<ref_ext><![CDATA[" . $produit['reference'] . "]]></ref_ext>\n" ;
|
|
$debutproduitxml .= "<ref_supplier><![CDATA[" . $produit['supplier_reference'] ."]]></ref_supplier>\n" ;
|
|
$debutproduitxml .= "<ean13><![CDATA[" . $produit['ean13'] . "]]></ean13>\n" ;
|
|
$debutproduitxml .= "<lib><![CDATA[" . $produit['nameproduct'] . "]]></lib>\n" ;
|
|
$debutproduitxml .= "<active><![CDATA[" . $produit['PRODUCT_ACTIVE'] . "]]></active>\n" ;
|
|
$debutproduitxml .= "<weight><![CDATA[" . $produit['weight'] . "]]></weight>\n" ;
|
|
$debutproduitxml .= "<weight_unit><![CDATA[Kg]]></weight_unit>\n" ;
|
|
$debutproduitxml .= "<volume><![CDATA[]]></volume>\n" ;
|
|
$debutproduitxml .= "<volume_unit><![CDATA[]]></volume_unit>\n" ;
|
|
$debutproduitxml .= "<quantity><![CDATA[" . $produit['quantity'] . "]]></quantity>\n" ;
|
|
$debutproduitxml .= "<image_link><![CDATA[" . $url ."]]></image_link>\n" ;
|
|
$debutproduitxml .= "<image_id><![CDATA[" . $id_image ."]]></image_id>\n" ;
|
|
$debutproduitxml .= "<supplier><![CDATA[" . $produit['namefournisseur'] . "]]></supplier>\n" ;
|
|
$debutproduitxml .= "<default_category><![CDATA[" . $this->getcategoryname($default_category) . "]]></default_category>\n" ;
|
|
$debutproduitxml .= "<root_category><![CDATA[" . $this->getrootcategory($default_category) . " - " . $this->getcategoryname($this->getrootcategory($default_category)) . "]]></root_category>\n" ;
|
|
|
|
$debutproduitxml .= "<categories>\n" ;
|
|
$categories = $this->getcategoriesproduct($id_product);
|
|
foreach($categories as $category)
|
|
{
|
|
$debutproduitxml .= "<category>\n" ;
|
|
$debutproduitxml .= "<name><![CDATA[" . $category . "]]></name>\n" ;
|
|
$debutproduitxml .= "</category>\n" ;
|
|
}
|
|
$debutproduitxml .= "</categories>\n" ;
|
|
$debutproduitxml .= "<virtual_product><![CDATA[" . $produit['virtuel'] . "]]></virtual_product>\n" ;
|
|
|
|
$debutproduitxml .= "<packs>\n" ;
|
|
$sql_pack = "select *
|
|
from "._DB_PREFIX_."pack
|
|
where id_product_pack = '$id_product' order by id_product_item asc ";
|
|
|
|
|
|
$LIST_PACK = Db::getInstance()->Query($sql_pack);
|
|
while($pack = Db::getInstance()->nextRow($LIST_PACK))
|
|
{
|
|
$debutproduitxml .= "<pack>\n" ;
|
|
$debutproduitxml .= "<child_id><![CDATA[" . $pack['id_product_item'] . "]]></child_id>\n" ;
|
|
$debutproduitxml .= "<child_qty><![CDATA[" . $pack['quantity'] . "]]></child_qty>\n" ;
|
|
$debutproduitxml .= "</pack>\n" ;
|
|
}
|
|
|
|
$debutproduitxml .= "</packs>\n" ;
|
|
$debutproduitxml .= "</line>\n" ;
|
|
fputs($f,$debutproduitxml);
|
|
|
|
$SQL_ATTRIBUT_PRODUITS = 'SELECT * FROM '._DB_PREFIX_.'product_attribute pa
|
|
WHERE pa.id_product ='.$produit['id_product'] ;
|
|
|
|
$LIST_ATTRIBUT_PRODUITS = Db::getInstance()->Query($SQL_ATTRIBUT_PRODUITS);
|
|
|
|
// $NOMBRE_ATTRIBUT_PRODUITS = Db::getInstance()->numRows($LIST_ATTRIBUT_PRODUITS);
|
|
|
|
while($attribut_produit = Db::getInstance()->nextRow($LIST_ATTRIBUT_PRODUITS))
|
|
{
|
|
//DEBUT D UN PRODUIT
|
|
|
|
$SQL_ATTRIBUT_NAME = 'SELECT al.name AS NAME_ATTR , pac.id_attribute AS ID_ATTR FROM '._DB_PREFIX_.'product_attribute_combination pac , '._DB_PREFIX_.'attribute_lang al
|
|
where al.id_attribute = pac.id_attribute
|
|
and al.id_lang = '.$id_lang.'
|
|
and pac.id_product_attribute = '.$attribut_produit['id_product_attribute'] ;
|
|
|
|
|
|
$LIST_ATTRIBUT_NAME = Db::getInstance()->Query($SQL_ATTRIBUT_NAME);
|
|
$name_attribut = '';
|
|
while($attribut_name = Db::getInstance()->nextRow($LIST_ATTRIBUT_NAME))
|
|
{
|
|
$id_attribute_4_group = $attribut_name['ID_ATTR'];
|
|
if($name_attribut == ''){$name_attribut .= $this->getgroupattributename($id_attribute_4_group,$id_lang)." : ".$attribut_name['NAME_ATTR'];}
|
|
else{$name_attribut .= " - ".$this->getgroupattributename($id_attribute_4_group,$id_lang)." : ".$attribut_name['NAME_ATTR'];}
|
|
}
|
|
|
|
|
|
$SQL_IMAGE_ATTR = 'SELECT '._DB_PREFIX_.'product_attribute_image.id_image
|
|
FROM '._DB_PREFIX_.'product_attribute_image where '._DB_PREFIX_.'product_attribute_image.id_product_attribute = '.$attribut_produit['id_product_attribute'] ;
|
|
$LIST_IMAGES_ATTR = Db::getInstance()->Query($SQL_IMAGE_ATTR);
|
|
|
|
$NB_LIST_IMAGES_ATTR = Db::getInstance()->numRows($LIST_IMAGES_ATTR);
|
|
|
|
|
|
|
|
if($NB_LIST_IMAGES_ATTR == '0')
|
|
{
|
|
$url_attr = '';
|
|
}
|
|
else
|
|
{
|
|
$row_id_image_attr = Db::getInstance()->getRow($SQL_IMAGE_ATTR);
|
|
$id_image_attr = $row_id_image_attr['id_image'];
|
|
$url_attr = $id_image_attr;
|
|
|
|
$url_attr = Link::getImageLink($produit['link_rewrite'], $produit['id_product'].'-'.$id_image_attr, 'home');
|
|
|
|
}
|
|
|
|
$debutproduitxml = "\n\n<line>\n" ;
|
|
$debutproduitxml .= "<ref><![CDATA[". $produit['id_product'] ."_". $attribut_produit['id_product_attribute'] . "]]></ref>\n" ;
|
|
$debutproduitxml .= "<ref_ext><![CDATA[" . $produit['reference'] ."]]></ref_ext>\n" ;
|
|
$debutproduitxml .= "<ref_supplier><![CDATA[" . $produit['supplier_reference'] ."]]></ref_supplier>\n" ;
|
|
$debutproduitxml .= "<ref_supplier_attr><![CDATA[" . $attribut_produit['supplier_reference'] ."]]></ref_supplier_attr>\n" ;
|
|
$debutproduitxml .= "<ref_ext_attr><![CDATA[" . $attribut_produit['reference'] ."]]></ref_ext_attr>\n" ;
|
|
$debutproduitxml .= "<ean13><![CDATA[" . $produit['ean13'] . "]]></ean13>\n" ;
|
|
$debutproduitxml .= "<ean13_attr><![CDATA[" . $attribut_produit['ean13'] . "]]></ean13_attr>\n" ;
|
|
$debutproduitxml .= "<lib><![CDATA[" . $produit['nameproduct'] . "]]></lib>\n" ;
|
|
$debutproduitxml .= "<lib_attr><![CDATA[" . $name_attribut . "]]></lib_attr>\n" ;
|
|
$debutproduitxml .= "<active><![CDATA[" . $produit['PRODUCT_ACTIVE'] . "]]></active>\n" ;
|
|
$debutproduitxml .= "<option1><![CDATA[" . $name_attribut . "]]></option1>\n" ;
|
|
$debutproduitxml .= "<weight><![CDATA[" . $attribut_produit['weight'] . "]]></weight>\n" ;
|
|
$debutproduitxml .= "<weight_unit><![CDATA[Kg]]></weight_unit>\n" ;
|
|
$debutproduitxml .= "<volume><![CDATA[]]></volume>\n" ;
|
|
$debutproduitxml .= "<volume_unit><![CDATA[]]></volume_unit>\n" ;
|
|
$debutproduitxml .= "<quantity><![CDATA[" . $attribut_produit['quantity'] . "]]></quantity>\n" ;
|
|
$debutproduitxml .= "<image_link><![CDATA[" . $url ."]]></image_link>\n" ;
|
|
$debutproduitxml .= "<image_id><![CDATA[" . $id_image ."]]></image_id>\n" ;
|
|
$debutproduitxml .= "<image_link_attr><![CDATA[" . $url_attr ."]]></image_link_attr>\n" ;
|
|
$debutproduitxml .= "<image_id_attr><![CDATA[" . $id_image_attr ."]]></image_id_attr>\n" ;
|
|
$debutproduitxml .= "<supplier><![CDATA[" . $produit['namefournisseur'] . "]]></supplier>\n" ;
|
|
$debutproduitxml .= "<default_category><![CDATA[" . $this->getcategoryname($default_category) . "]]></default_category>\n" ;
|
|
$debutproduitxml .= "<root_category><![CDATA[" . $this->getrootcategory($default_category) . " - " . $this->getcategoryname($this->getrootcategory($default_category)) . "]]></root_category>\n" ;
|
|
$debutproduitxml .= "<virtual_product><![CDATA[" . $produit['virtuel'] . "]]></virtual_product>\n" ;
|
|
$debutproduitxml .= "</line>\n" ;
|
|
|
|
fputs($f,$debutproduitxml);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$entetpackxml = "</articles>\n" ;
|
|
|
|
fputs($f,$entetpackxml);
|
|
|
|
$finxml = "</references>\n" ;
|
|
fputs($f,$finxml);
|
|
|
|
fclose($f);
|
|
|
|
|
|
$log_articles .= "Nb articles : ".$NOMBRELIGNE_PRODUITS." | " ;
|
|
|
|
|
|
|
|
// Création de la connexion
|
|
|
|
$conn_id = ftp_connect($this->getConfig("FTP_IP"));
|
|
|
|
// Authentification avec nom de compte et mot de passe
|
|
$login_result = ftp_login($conn_id, $this->getConfig("FTP_login"), $this->getConfig("FTP_password"));
|
|
|
|
//mode passif
|
|
ftp_pasv($conn_id,1);
|
|
|
|
// Vérification de la connexion
|
|
if ((!$conn_id) || (!$login_result)) {
|
|
$log_articles .= "Connexion FTP KO ";
|
|
}
|
|
else
|
|
{
|
|
|
|
$log_articles .= "Connexion FTP OK ";
|
|
// Passage ds le répertoire DES ARTICLES
|
|
|
|
ftp_chdir($conn_id, $this->getConfig("article_directory"));
|
|
|
|
// Liste les fichiers du répertoire
|
|
|
|
if( ftp_put($conn_id, $FICHIER, $FICHIER_A_ENVOYER, FTP_BINARY) )
|
|
{
|
|
$log_articles .= " | Transfert fichier ".$FICHIER;
|
|
|
|
}
|
|
else
|
|
{
|
|
$log_articles .= " Transfert fichier KO";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unlink($FICHIER_A_ENVOYER);
|
|
|
|
echo "Log : ".$log_articles;
|
|
|
|
Logger::addLog($log_articles, 1, 101, 'Logging object');
|
|
|
|
|
|
// Fermeture de la connexion FTP.
|
|
ftp_quit($conn_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/////////////////////////////
|
|
//////// ENVOI DES COMMANDES
|
|
/////////////////////////////
|
|
|
|
|
|
public function getContentCommandes()
|
|
{
|
|
if($this->getConfig("order_flag")=='1')
|
|
{
|
|
|
|
$DATE_LOG = date("Ymd H:i:s");
|
|
|
|
// Création de la connexion
|
|
$conn_id = ftp_connect($this->getConfig("FTP_IP"));
|
|
|
|
// Authentification avec nom de compte et mot de passe
|
|
$login_result = ftp_login($conn_id, $this->getConfig("FTP_login"), $this->getConfig("FTP_password"));
|
|
|
|
//mode passif
|
|
ftp_pasv($conn_id,1);
|
|
|
|
// Vérification de la connexion
|
|
if ((!$conn_id) || (!$login_result)) {
|
|
$log_orders = "Neolys Commandes | ".$DATE_LOG." | Connexion FTP KO ";
|
|
}
|
|
else
|
|
{
|
|
|
|
// DONNE LE NUMERO DE COMMANDE
|
|
|
|
$SQL_COMMANDES = 'SELECT '._DB_PREFIX_.'order_history.id_order,
|
|
MAX( '._DB_PREFIX_.'order_history.id_order_state ) AS DernierEtat,
|
|
'._DB_PREFIX_.'orders.invoice_number,
|
|
'._DB_PREFIX_.'orders.date_add,
|
|
'._DB_PREFIX_.'orders.total_shipping,
|
|
'._DB_PREFIX_.'orders.total_paid_real,
|
|
'._DB_PREFIX_.'orders.total_paid,
|
|
'._DB_PREFIX_.'orders.total_paid_tax_incl,
|
|
'._DB_PREFIX_.'orders.total_paid_tax_excl,
|
|
'._DB_PREFIX_.'orders.total_discounts,
|
|
'._DB_PREFIX_.'orders.total_discounts_tax_incl,
|
|
'._DB_PREFIX_.'orders.total_discounts_tax_excl,
|
|
'._DB_PREFIX_.'orders.total_products,
|
|
'._DB_PREFIX_.'orders.total_shipping_tax_incl,
|
|
'._DB_PREFIX_.'orders.total_shipping_tax_excl,
|
|
'._DB_PREFIX_.'orders.payment,
|
|
'._DB_PREFIX_.'orders.reference,
|
|
'._DB_PREFIX_.'orders.id_address_delivery,
|
|
'._DB_PREFIX_.'orders.id_address_invoice,
|
|
'._DB_PREFIX_.'orders.id_cart,
|
|
'._DB_PREFIX_.'orders.id_customer,
|
|
'._DB_PREFIX_.'customer.lastname ,
|
|
'._DB_PREFIX_.'customer.firstname ,
|
|
'._DB_PREFIX_.'customer.email ,
|
|
'._DB_PREFIX_.'carrier.id_carrier,
|
|
'._DB_PREFIX_.'carrier.name,
|
|
'._DB_PREFIX_.'carrier.id_reference,
|
|
'._DB_PREFIX_.'cart.gift,
|
|
'._DB_PREFIX_.'cart.recyclable,
|
|
'._DB_PREFIX_.'cart.gift_message
|
|
FROM '._DB_PREFIX_.'order_history
|
|
LEFT JOIN '._DB_PREFIX_.'orders ON '._DB_PREFIX_.'order_history.id_order = '._DB_PREFIX_.'orders.id_order
|
|
LEFT JOIN '._DB_PREFIX_.'customer ON '._DB_PREFIX_.'customer.id_customer = '._DB_PREFIX_.'orders.id_customer
|
|
LEFT JOIN '._DB_PREFIX_.'carrier ON '._DB_PREFIX_.'carrier.id_carrier = '._DB_PREFIX_.'orders.id_carrier
|
|
LEFT JOIN '._DB_PREFIX_.'cart ON '._DB_PREFIX_.'cart.id_cart = '._DB_PREFIX_.'orders.id_cart
|
|
WHERE '._DB_PREFIX_.'order_history.id_order_state = 2
|
|
GROUP BY '._DB_PREFIX_.'order_history.id_order
|
|
HAVING MAX( '._DB_PREFIX_.'order_history.id_order_state ) in (2,8,9,10,11) ';
|
|
|
|
|
|
|
|
|
|
echo $SQL_COMMANDES . "<br>" ;
|
|
$LIST_COMMANDES = Db::getInstance()->Query($SQL_COMMANDES);
|
|
|
|
$nb_commandes = Db::getInstance()->numRows($LIST_COMMANDES);
|
|
echo $nb_commandes . "<br>" ;
|
|
|
|
if($nb_commandes > 0)
|
|
{
|
|
//$URL_SITE = "http://" . Configuration::get('CANONICAL_URL') ;
|
|
|
|
$DATE = date('YmdHis');
|
|
$FICHIER = "orders_". $DATE .".xml";
|
|
|
|
$PATH = dirname(__FILE__) . "/data/" ;
|
|
$FICHIER_A_ENVOYER = $PATH . $FICHIER ;
|
|
|
|
$f = fopen($FICHIER_A_ENVOYER,"w");
|
|
|
|
//DEBUT DU FICHIER
|
|
// Antadis 12667 - Change encoding
|
|
$debutxml = '<?xml version="1.0" encoding="UTF-8" ?>' ;
|
|
$debutxml .= "\n" ;
|
|
$debutxml .= '<orders version="'.$this->version.'">' ;
|
|
$debutxml .= "\n" ;
|
|
fputs($f,$debutxml);
|
|
|
|
}
|
|
|
|
|
|
$orderlist = array();
|
|
|
|
$nb_commandes_0 = 0 ;
|
|
|
|
while($commande = Db::getInstance()->nextRow($LIST_COMMANDES))
|
|
{
|
|
// TEST SUR LE DERNIER STATUT
|
|
$SQL_LAST_STATUS = 'SELECT id_order_state FROM '._DB_PREFIX_.'order_history where id_order = '.$commande['id_order'].' ORDER BY id_order_history desc ';
|
|
//$LIST_LAST_STATUS = Db::getInstance()->Query($SQL_LAST_STATUS);
|
|
$ROW_LAST_STATUS = Db::getInstance()->getRow($SQL_LAST_STATUS);
|
|
$LAST_STATUS = $ROW_LAST_STATUS['id_order_state'];
|
|
//$LAST_STATUS = mysql_result($LIST_LAST_STATUS,0,"id_order_state");
|
|
echo $LAST_STATUS . "<br>" ;
|
|
if($LAST_STATUS == '2' )
|
|
{
|
|
$nb_commandes_0 ++ ;
|
|
$cart_id = $commande['id_cart'];
|
|
$order_id = $commande['id_order'];
|
|
array_push($orderlist, $order_id);
|
|
//DEBUT D UNE COMMANDE
|
|
$debutcommandexml = "\n\n<order>\n" ;
|
|
$debutcommandexml .= "<header>\n" ;
|
|
$debutcommandexml .= "<num>" . $commande['id_order'] . "</num>\n" ;
|
|
$debutcommandexml .= "<reference_order>" . $commande['reference'] . "</reference_order>\n" ;
|
|
$debutcommandexml .= "<operation>Commande Ecommerce</operation>\n" ;
|
|
$debutcommandexml .= "<date>" . $commande['date_add'] . "</date>\n" ;
|
|
$debutcommandexml .= "<invoice_num>" . $commande['invoice_number'] . "</invoice_num>\n" ;
|
|
|
|
//BLOCK MESSAGE
|
|
//$debutcommandexml .= "<messages>\n" ;
|
|
//$debutcommandexml .= "<msg></msg>\n" ;
|
|
//$debutcommandexml .= "</messages>\n" ;
|
|
fputs($f,$debutcommandexml);
|
|
|
|
//BLOCK CUSTOMER
|
|
$orderxml = "<customer>\n" ;
|
|
$orderxml .= "<name><![CDATA[" .$commande['lastname']. "]]></name>\n" ;
|
|
$orderxml .= "<firstname><![CDATA[" .$commande['firstname']. "]]></firstname>\n" ;
|
|
$orderxml .= "<email><![CDATA[" .$commande['email']. "]]></email>\n" ;
|
|
$orderxml .= "<num></num>\n" ;
|
|
|
|
|
|
|
|
// ADRESSE DE FACTURATION (id_address_invoice)
|
|
$SQL_ADRESSE_FACTURATION = 'SELECT
|
|
'._DB_PREFIX_.'address.company ,
|
|
'._DB_PREFIX_.'address.lastname ,
|
|
'._DB_PREFIX_.'address.firstname ,
|
|
'._DB_PREFIX_.'address.address1 ,
|
|
'._DB_PREFIX_.'address.address2 ,
|
|
'._DB_PREFIX_.'address.postcode ,
|
|
'._DB_PREFIX_.'address.city ,
|
|
'._DB_PREFIX_.'address.phone ,
|
|
'._DB_PREFIX_.'address.phone_mobile ,
|
|
'._DB_PREFIX_.'country.iso_code AS COUNTRY_CODE ,
|
|
'._DB_PREFIX_.'state.iso_code AS STATE_CODE
|
|
FROM '._DB_PREFIX_.'address
|
|
LEFT JOIN '._DB_PREFIX_.'country ON '._DB_PREFIX_.'country.id_country = '._DB_PREFIX_.'address.id_country
|
|
LEFT JOIN '._DB_PREFIX_.'state ON '._DB_PREFIX_.'state.id_state = '._DB_PREFIX_.'address.id_state
|
|
WHERE
|
|
'._DB_PREFIX_.'address.id_address = '. $commande['id_address_invoice'] .' limit 1';
|
|
|
|
//echo $SQL_ADRESSE_FACTURATION . "\n" ;
|
|
$LIST_ADRESSE_FACTURATION = Db::getInstance()->Query($SQL_ADRESSE_FACTURATION);
|
|
while($adresse_facturation = Db::getInstance()->nextRow($LIST_ADRESSE_FACTURATION))
|
|
{
|
|
//BLOCK SHIPPING ADRESS
|
|
$orderxml .= "<invoice_adress>\n" ;
|
|
$orderxml .= "<corp_name><![CDATA[" .$adresse_facturation['company']. "]]></corp_name>\n" ;
|
|
$orderxml .= "<name><![CDATA[" .$adresse_facturation['lastname']. "]]></name>\n" ;
|
|
$orderxml .= "<firstname><![CDATA[" .$adresse_facturation['firstname']. "]]></firstname>\n" ;
|
|
$orderxml .= "<adr1><![CDATA[" .$adresse_facturation['address1']. "]]></adr1>\n" ;
|
|
$orderxml .= "<adr2><![CDATA[" .$adresse_facturation['address2']. "]]></adr2>\n" ;
|
|
$orderxml .= "<adr3><![CDATA[]]></adr3>\n" ;
|
|
$orderxml .= "<zip><![CDATA[" .$adresse_facturation['postcode']. "]]></zip>\n" ;
|
|
$orderxml .= "<city><![CDATA[" .$adresse_facturation['city']. "]]></city>\n" ;
|
|
$orderxml .= "<country><![CDATA[" .$adresse_facturation['COUNTRY_CODE']. "]]></country>\n" ;
|
|
$orderxml .= "<state_province><![CDATA[" .$adresse_facturation['STATE_CODE']. "]]></state_province>\n" ;
|
|
$orderxml .= "<email>" .$commande['email']. "</email>\n" ;
|
|
$orderxml .= "<phone>" .$adresse_facturation['phone']. "</phone>\n" ;
|
|
$orderxml .= "<mobile_phone>" .$adresse_facturation['phone_mobile']. "</mobile_phone>\n" ;
|
|
$orderxml .= "</invoice_adress>\n" ;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ADRESSE LIVRAISON (id_address_delivery)
|
|
$SQL_ADRESSE_LIVRAISON = 'SELECT
|
|
'._DB_PREFIX_.'address.company ,
|
|
'._DB_PREFIX_.'address.lastname ,
|
|
'._DB_PREFIX_.'address.firstname ,
|
|
'._DB_PREFIX_.'address.address1 ,
|
|
'._DB_PREFIX_.'address.address2 ,
|
|
'._DB_PREFIX_.'address.postcode ,
|
|
'._DB_PREFIX_.'address.other ,
|
|
'._DB_PREFIX_.'address.city ,
|
|
'._DB_PREFIX_.'address.phone ,
|
|
'._DB_PREFIX_.'address.phone_mobile ,
|
|
'._DB_PREFIX_.'country.iso_code AS COUNTRY_CODE ,
|
|
'._DB_PREFIX_.'state.iso_code AS STATE_CODE
|
|
FROM '._DB_PREFIX_.'address
|
|
LEFT JOIN '._DB_PREFIX_.'country ON '._DB_PREFIX_.'country.id_country = '._DB_PREFIX_.'address.id_country
|
|
LEFT JOIN '._DB_PREFIX_.'state ON '._DB_PREFIX_.'state.id_state = '._DB_PREFIX_.'address.id_state
|
|
WHERE
|
|
'._DB_PREFIX_.'address.id_address = '. $commande['id_address_delivery'] .' limit 1';
|
|
|
|
//echo $SQL_ADRESSE_LIVRAISON . "\n" ;
|
|
$LIST_ADRESSE_LIVRAISON = Db::getInstance()->Query($SQL_ADRESSE_LIVRAISON);
|
|
while($adresse_livraison = Db::getInstance()->nextRow($LIST_ADRESSE_LIVRAISON))
|
|
{
|
|
|
|
//BLOCK SHIPPING ADRESS
|
|
$orderxml .= "<shipping_adress>\n" ;
|
|
$orderxml .= "<corp_name><![CDATA[" .$adresse_livraison['company']. "]]></corp_name>\n" ;
|
|
$orderxml .= "<name><![CDATA[" .$adresse_livraison['lastname']. "]]></name>\n" ;
|
|
$orderxml .= "<firstname><![CDATA[" .$adresse_livraison['firstname']. "]]></firstname>\n" ;
|
|
$orderxml .= "<adr1><![CDATA[" .$adresse_livraison['address1']. "]]></adr1>\n" ;
|
|
$orderxml .= "<adr2><![CDATA[" .$adresse_livraison['address2']. "]]></adr2>\n" ;
|
|
$orderxml .= "<adr3><![CDATA[" .$adresse_livraison['other']. "]]></adr3>\n" ;
|
|
$orderxml .= "<zip><![CDATA[" .$adresse_livraison['postcode']. "]]></zip>\n" ;
|
|
$orderxml .= "<city><![CDATA[" .$adresse_livraison['city']. "]]></city>\n" ;
|
|
$orderxml .= "<country><![CDATA[" .$adresse_livraison['COUNTRY_CODE']. "]]></country>\n" ;
|
|
$orderxml .= "<state_province><![CDATA[" .$adresse_livraison['STATE_CODE']. "]]></state_province>\n" ;
|
|
$orderxml .= "<email>" .$commande['email']. "</email>\n" ;
|
|
$orderxml .= "<phone>" .$adresse_livraison['phone']. "</phone>\n" ;
|
|
$orderxml .= "<mobile_phone>" .$adresse_livraison['phone_mobile']. "</mobile_phone>\n" ;
|
|
$orderxml .= "</shipping_adress>\n" ;
|
|
$orderxml .= "<shipping_info><![CDATA[" .$adresse_livraison['other']. "]]></shipping_info>\n" ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//BLOCK FIN CUSTOMER
|
|
$orderxml .= "</customer>\n" ;
|
|
$orderxml .= "</header>\n" ;
|
|
|
|
|
|
|
|
//BLOCK ARTICLES
|
|
$SQL_ARTICLES = 'SELECT * FROM '._DB_PREFIX_.'order_detail
|
|
JOIN '._DB_PREFIX_.'product
|
|
ON '._DB_PREFIX_.'product.id_product = '._DB_PREFIX_.'order_detail.product_id
|
|
WHERE '._DB_PREFIX_.'order_detail.id_order = '.$commande['id_order'].' ';
|
|
|
|
//echo $SQL_ARTICLES . "\n" ;
|
|
$LIST_ARTICLES = Db::getInstance()->Query($SQL_ARTICLES);
|
|
$NOMBRE_ARTICLES = Db::getInstance()->numRows($LIST_ARTICLES);
|
|
|
|
|
|
$orderxml .= "<articles count=\"" . $NOMBRE_ARTICLES . "\">\n" ;
|
|
|
|
while($article = Db::getInstance()->nextRow($LIST_ARTICLES))
|
|
{
|
|
//$tax_amount = $article['product_price'] * $article['tax_rate'] / 100 * $article['product_quantity'] ;
|
|
$tax_amount = $article['total_price_tax_incl'] - $article['total_price_tax_excl'];
|
|
$tax_rate = (100 * $tax_amount) / $article['total_price_tax_excl'] ;
|
|
$tax_rate = round($tax_rate, 1);
|
|
//$total_price_ttc = ( $article['product_price'] * $article['product_quantity'] ) + $tax_amount ;
|
|
$total_price_ttc = $article['total_price_tax_incl'];
|
|
//$total_price_ht = $article['product_price'] * $article['product_quantity'] ;
|
|
$total_price_ht = $article['total_price_tax_excl'];
|
|
$unit_price_ht = $article['product_price'];
|
|
$unit_price_ht = round($unit_price_ht, 2);
|
|
$tax_amount_arrondit = round($tax_amount, 2);
|
|
$total_price_ttc_arrondit = round($total_price_ttc, 2);
|
|
$total_price_ht_arrondit = round($total_price_ht, 2);
|
|
|
|
$reduction_amount_tax_incl = $article['reduction_amount_tax_incl'];
|
|
$reduction_amount_tax_excl = $article['reduction_amount_tax_excl'];
|
|
$reduction_amount = $article['reduction_amount'];
|
|
|
|
$orderxml .= "<line>\n" ;
|
|
|
|
if ($article['product_attribute_id'] == 0 )
|
|
{
|
|
$orderxml .= "<ref><![CDATA[" .$article['product_id']. "]]></ref>\n" ;
|
|
}
|
|
else
|
|
{
|
|
$orderxml .= "<ref><![CDATA[". $article['product_id'] ."_". $article['product_attribute_id'] . "]]></ref>\n" ;
|
|
}
|
|
$orderxml .= "<sku><![CDATA[" .$article['reference']. "]]></sku>\n" ; //SKU
|
|
$orderxml .= "<current_qty>" .$article['product_quantity']. "</current_qty>\n" ; //Quantite commande de ce produit
|
|
$orderxml .= "<lib><![CDATA[" .$article['product_name']. "]]></lib>\n" ;
|
|
$orderxml .= "<total_price_ht>" .$total_price_ht_arrondit. "</total_price_ht>\n" ;
|
|
$orderxml .= "<total_price_ttc>" .$total_price_ttc_arrondit. "</total_price_ttc>\n" ;
|
|
$orderxml .= "<unit_price_ht>" .$unit_price_ht. "</unit_price_ht>\n" ;
|
|
$orderxml .= "<tax_rate>" .$tax_rate. "</tax_rate>\n" ;
|
|
$orderxml .= "<tax_amount>" .$tax_amount_arrondit. "</tax_amount>\n" ;
|
|
$orderxml .= "<reduction_amount>" .round($reduction_amount, 2). "</reduction_amount>\n" ;
|
|
$orderxml .= "<reduction_amount_tax_incl>" .round($reduction_amount_tax_incl, 2). "</reduction_amount_tax_incl>\n" ;
|
|
$orderxml .= "<reduction_amount_tax_excl>" .round($reduction_amount_tax_excl, 2). "</reduction_amount_tax_excl>\n" ;
|
|
|
|
if ($article['product_attribute_id'] == 0 )
|
|
{
|
|
$id_product = $article['product_id'];
|
|
$orderxml .= "<packs>\n" ;
|
|
$sql_pack = "select *
|
|
from "._DB_PREFIX_."pack
|
|
where id_product_pack = '$id_product' order by id_product_item asc ";
|
|
|
|
$LIST_PACK = Db::getInstance()->Query($sql_pack);
|
|
while($pack = Db::getInstance()->nextRow($LIST_PACK))
|
|
{
|
|
$orderxml .= "<pack>\n" ;
|
|
$orderxml .= "<child_id><![CDATA[" . $pack['id_product_item'] . "]]></child_id>\n" ;
|
|
$orderxml .= "<child_qty><![CDATA[" . $pack['quantity'] . "]]></child_qty>\n" ;
|
|
$orderxml .= "</pack>\n" ;
|
|
}
|
|
|
|
$orderxml .= "</packs>\n" ;
|
|
}
|
|
|
|
$orderxml .= "</line>\n" ;
|
|
|
|
}
|
|
$orderxml .= "</articles>\n" ;
|
|
|
|
|
|
|
|
//BLOCK FOOTER
|
|
|
|
$shipping_details = $this->getshippingdetails($cart_id);
|
|
|
|
$orderxml .= "<footer>\n" ;
|
|
$orderxml .= "<code_promo><![CDATA[]]></code_promo>\n" ;
|
|
$orderxml .= "<gift><![CDATA[" .$commande['gift']. "]]></gift>\n" ;
|
|
$orderxml .= "<gift_message><![CDATA[" .$commande['gift_message']. "]]></gift_message>\n" ;
|
|
$orderxml .= "<recyclable><![CDATA[" .$commande['recyclable']. "]]></recyclable>\n" ;
|
|
$orderxml .= "<shipping_mode><![CDATA[" .$commande['id_carrier']. "]]></shipping_mode>\n" ;
|
|
$orderxml .= "<shipping_mode_reference><![CDATA[" .$commande['id_reference']. "]]></shipping_mode_reference>\n" ;
|
|
$orderxml .= "<shipping_mode_option><![CDATA[" .$shipping_details['1']. "]]></shipping_mode_option>\n" ;
|
|
$orderxml .= "<pick_up>\n" ;
|
|
$orderxml .= "<pick_up_num><![CDATA[" .$shipping_details['2']. "]]></pick_up_num>\n" ;
|
|
$orderxml .= "<pick_up_ad1><![CDATA[ ]]> </pick_up_ad1>\n" ;
|
|
$orderxml .= "<pick_up_zip><![CDATA[ ]]></pick_up_zip>\n" ;
|
|
$orderxml .= "<pick_up_country><![CDATA[ ]]></pick_up_country>\n" ;
|
|
$orderxml .= "<pick_up_cephonenumber><![CDATA[" .$shipping_details['3']. "]]></pick_up_cephonenumber>\n" ;
|
|
$orderxml .= "<pick_up_ceemail><![CDATA[" .$shipping_details['4']. "]]></pick_up_ceemail>\n" ;
|
|
$orderxml .= "<pick_up_contact_name><![CDATA[" .$shipping_details['9']. "]]></pick_up_contact_name>\n" ;
|
|
$orderxml .= "<pick_up_contact_fname><![CDATA[" .$shipping_details['10']. "]]></pick_up_contact_fname>\n" ;
|
|
$orderxml .= "<pick_up_ce_delivery_information><![CDATA[" .$shipping_details['6']. "]]></pick_up_ce_delivery_information>\n" ;
|
|
$orderxml .= "<pick_up_ce_doorcode1><![CDATA[" .$shipping_details['7']. "]]></pick_up_ce_doorcode1>\n" ;
|
|
$orderxml .= "<pick_up_ce_doorcode2><![CDATA[" .$shipping_details['8']. "]]></pick_up_ce_doorcode2>\n" ;
|
|
$orderxml .= "</pick_up>\n" ;
|
|
$orderxml .= "<total_discounts><![CDATA[" .$commande['total_discounts']. "]]></total_discounts>\n" ;
|
|
$orderxml .= "<total_discounts_tax_incl><![CDATA[" .$commande['total_discounts_tax_incl']. "]]></total_discounts_tax_incl>\n" ;
|
|
$orderxml .= "<total_discounts_tax_excl><![CDATA[" .$commande['total_discounts_tax_excl']. "]]></total_discounts_tax_excl>\n" ;
|
|
$orderxml .= "<shipping_lib><![CDATA[" .$commande['name']. "]]></shipping_lib>\n" ;
|
|
$orderxml .= "<shipping_price><![CDATA[" .$commande['total_shipping']. "]]></shipping_price>\n" ;
|
|
$orderxml .= "<total_shipping_tax_incl><![CDATA[" .$commande['total_shipping_tax_incl']. "]]></total_shipping_tax_incl>\n" ;
|
|
$orderxml .= "<total_shipping_tax_excl><![CDATA[" .$commande['total_shipping_tax_excl']. "]]></total_shipping_tax_excl>\n" ;
|
|
$orderxml .= "<total_products><![CDATA[" .$commande['total_products']. "]]></total_products>\n" ;
|
|
$orderxml .= "<total_paid_tax_incl><![CDATA[" .$commande['total_paid_tax_incl']. "]]></total_paid_tax_incl>\n" ;
|
|
$orderxml .= "<total_paid_tax_excl><![CDATA[" .$commande['total_paid_tax_excl']. "]]></total_paid_tax_excl>\n" ;
|
|
$orderxml .= "<total_paid><![CDATA[" .$commande['total_paid']. "]]></total_paid>\n" ;
|
|
$orderxml .= "<total_invoice><![CDATA[" .$commande['total_paid_real']. "]]></total_invoice>\n" ;
|
|
$orderxml .= "<pay_method><![CDATA[" .$commande['payment']. "]]></pay_method>\n" ;
|
|
$orderxml .= "<bl_flag>1</bl_flag>\n" ;
|
|
$orderxml .= "<bill_flag>0</bill_flag>\n" ;
|
|
$orderxml .= "</footer>\n" ;
|
|
$orderxml .= "<messages>\n" ;
|
|
$id_customer = $commande['id_customer'];
|
|
$id_order = $commande['id_order'];
|
|
$messages = $this->getordermessages($id_order,$id_customer);
|
|
foreach($messages as $message)
|
|
{
|
|
$orderxml .= "<message>\n" ;
|
|
$orderxml .= "<![CDATA[" . $message . "]]>\n" ;
|
|
$orderxml .= "</message>\n" ;
|
|
}
|
|
$orderxml .= "</messages>\n" ;
|
|
|
|
$orderxml .= "</order>\n" ;
|
|
|
|
fputs($f,$orderxml);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($nb_commandes > 0)
|
|
{
|
|
$finxml = "\n</orders>" ;
|
|
fputs($f,$finxml);
|
|
|
|
|
|
fclose($f);
|
|
}
|
|
$log_orders = "Neolys Commandes | ".$DATE_LOG." | Connexion FTP OK | ";
|
|
$log_orders .= "Nb commandes : ".$nb_commandes_0 ;
|
|
|
|
if($nb_commandes > 0)
|
|
{
|
|
|
|
|
|
// Passage ds le répertoire DES ARTICLES
|
|
|
|
ftp_chdir($conn_id, $this->getConfig("order_directory"));
|
|
|
|
// Liste les fichiers du répertoire
|
|
|
|
if( ftp_put($conn_id, $FICHIER, $FICHIER_A_ENVOYER, FTP_BINARY) )
|
|
{
|
|
$log_orders .= " | Transfert fichier ".$FICHIER;
|
|
|
|
unlink($FICHIER_A_ENVOYER);
|
|
|
|
foreach($orderlist as $order_id)
|
|
{
|
|
$orderHistory = new OrderHistory();
|
|
$orderHistory->id_order = $order_id;
|
|
$orderHistory->changeIdOrderState(intval(_PS_OS_PREPARATION_), intval($orderHistory->id_order), true);
|
|
$orderHistory->addWithemail();
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
$log_orders .= " Transfert fichier KO";
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// Fermeture de la connexion FTP.
|
|
ftp_quit($conn_id);
|
|
|
|
|
|
}
|
|
|
|
echo "Log : ".$log_orders;
|
|
|
|
Logger::addLog($log_orders, 1, 101, 'Logging object');
|
|
|
|
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////
|
|
////////// IMPORT STOCK
|
|
//////////////////////////////////////////
|
|
|
|
|
|
public function updateStock()
|
|
{
|
|
|
|
if($this->getConfig("stock_flag")=='1')
|
|
{
|
|
|
|
$DATE_LOG = date("Ymd H:i:s");
|
|
|
|
$log_stock = $DATE_LOG." | ";
|
|
|
|
$transfert_status = '';
|
|
|
|
// Création de la connexion
|
|
$conn_id = ftp_connect($this->getConfig("FTP_IP"));
|
|
|
|
// Authentification avec nom de compte et mot de passe
|
|
$login_result = ftp_login($conn_id, $this->getConfig("FTP_login"), $this->getConfig("FTP_password"));
|
|
|
|
//mode passif
|
|
ftp_pasv($conn_id,1);
|
|
|
|
// Vérification de la connexion
|
|
if ((!$conn_id) || (!$login_result)) {
|
|
$log_stock .= 'Connexion FTP KO';
|
|
die;
|
|
}
|
|
else
|
|
{
|
|
$log_stock .= 'Connexion FTP OK';
|
|
ftp_chdir($conn_id, $this->getConfig("stock_directory"));
|
|
|
|
$liste_fichiers_stock = ftp_nlist($conn_id, ".");
|
|
|
|
sort($liste_fichiers_stock);
|
|
foreach($liste_fichiers_stock as $fichier_stock_a_telecharger)
|
|
{
|
|
}
|
|
|
|
$date = date('Ymd');
|
|
if(Tools::substr($fichier_stock_a_telecharger,6,8) == $date and Tools::substr($fichier_stock_a_telecharger,0,5) == 'stock')
|
|
{
|
|
$directory_ps = dirname(__FILE__).'/data/';
|
|
|
|
if(ftp_get($conn_id, $directory_ps.$fichier_stock_a_telecharger, $fichier_stock_a_telecharger, FTP_BINARY))
|
|
{
|
|
$log_stock .= ' | Transfert fichier '.$fichier_stock_a_telecharger.' OK';
|
|
$transfert_status = '1';
|
|
}
|
|
else{$log_stock .= ' | Transfert fichier '.$fichier_stock_a_telecharger.' KO';}
|
|
}
|
|
else
|
|
{
|
|
$log_stock .= ' | Aucun fichier a transferer';
|
|
}
|
|
|
|
}
|
|
|
|
// Fermeture de la connexion FTP.
|
|
ftp_quit($conn_id);
|
|
|
|
|
|
if($transfert_status == '1')
|
|
{
|
|
$fichier_a_traiter = dirname(__FILE__).'/data/'.$fichier_stock_a_telecharger;
|
|
|
|
$file_content=file($fichier_a_traiter);
|
|
|
|
$nb_lines = count($file_content);
|
|
|
|
for( $i = 0 ; $i < count($file_content); $i++ )
|
|
{
|
|
$file_contents = explode(";",$file_content[$i]);
|
|
|
|
$ref_art = addslashes($file_contents[1]);
|
|
$ref_art_l = explode("_",$ref_art);
|
|
$id_product = $ref_art_l[0];
|
|
$id_product_attribute = $ref_art_l[1];
|
|
$stock = addslashes($file_contents[2]);
|
|
$poids = addslashes($file_contents[3]);
|
|
$poids = $poids / 1000 ;
|
|
|
|
if($poids > 0)
|
|
{
|
|
if($id_product_attribute == '')
|
|
{
|
|
$sql='UPDATE '._DB_PREFIX_.'product AS P set P.weight = '.$poids.'
|
|
where id_product = '.$id_product;
|
|
|
|
$sql2='UPDATE '._DB_PREFIX_.'stock_available AS P set P.quantity = '.$stock.'
|
|
where id_product = '.$id_product.' and id_product_attribute = 0 ';
|
|
|
|
}
|
|
else
|
|
{
|
|
$sql='UPDATE '._DB_PREFIX_.'product_attribute AS PA set PA.weight = '.$poids.'
|
|
where PA.id_product_attribute = '.$id_product_attribute.' and PA.id_product = '.$id_product;
|
|
|
|
$sql2='UPDATE '._DB_PREFIX_.'stock_available AS P set P.quantity = '.$stock.'
|
|
where id_product = '.$id_product.' and id_product_attribute = '.$id_product_attribute ;
|
|
}
|
|
|
|
Db::getInstance()->Execute($sql);
|
|
Db::getInstance()->Execute($sql2);
|
|
}
|
|
elseif($poids == '0')
|
|
{
|
|
if($id_product_attribute == '')
|
|
{
|
|
$sql='UPDATE '._DB_PREFIX_.'stock_available AS P set P.quantity = '.$stock.'
|
|
where id_product = '.$id_product.' and id_product_attribute = 0 ';
|
|
|
|
}
|
|
else
|
|
{
|
|
$sql='UPDATE '._DB_PREFIX_.'stock_available AS P set P.quantity = '.$stock.'
|
|
where id_product = '.$id_product.' and id_product_attribute = '.$id_product_attribute ;
|
|
}
|
|
|
|
Db::getInstance()->Execute($sql);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
$log_stock .= ' | MAJ : '.$nb_lines.' records';
|
|
|
|
}
|
|
|
|
echo "Log : ".$log_stock;
|
|
|
|
Logger::addLog($log_stock, 1, 101, 'Logging object');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
///////////////// STATUTS
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
public function updateStatuts()
|
|
{
|
|
|
|
if($this->getConfig("statuts_flag")=='1')
|
|
{
|
|
|
|
$DATE = date("Ymd H:i:s");
|
|
|
|
// ACCES WEBSERVICE
|
|
|
|
$postdata = http_build_query(
|
|
array(
|
|
'ws_key' => $this->getConfig("WS_KEY"),
|
|
'content' => 'ORDER_HISTORY',
|
|
'is_test' => '0'
|
|
)
|
|
);
|
|
|
|
$opts = array('http' =>
|
|
array(
|
|
'method' => 'POST',
|
|
'header' => 'Content-type: application/x-www-form-urlencoded',
|
|
'content' => $postdata
|
|
)
|
|
);
|
|
|
|
$context = stream_context_create($opts);
|
|
|
|
$link = "http://".$this->getConfig("FTP_IP")."/webservice/webservices.php";
|
|
|
|
$result = Tools::file_get_contents($link, false, $context);
|
|
|
|
echo $result;
|
|
|
|
$xml = simplexml_load_string($result);
|
|
$nb_done = 0;
|
|
$p_cnt = count($xml->EVENT);
|
|
for($i = 0; $i < $p_cnt; $i++) {
|
|
$event = $xml->EVENT[$i];
|
|
$event_type = '' ;
|
|
$event_type = $event->EVENT_TYPE ;
|
|
$order_id = '' ;
|
|
$order_id = $event->ORDER_ID ;
|
|
$id_colis = '' ;
|
|
$id_colis = $event->ID_COLIS ;
|
|
//$event_date = '' ;
|
|
//$event_date = $event->EVENT_DATE ;
|
|
|
|
$SQL = 'SELECT * FROM '._DB_PREFIX_.'orders where id_order = '.$order_id.'
|
|
ORDER BY '._DB_PREFIX_.'orders.id_order ASC';
|
|
|
|
$RESULTAT_SQL = Db::getInstance()->Query($SQL);
|
|
$NOMBRELIGNE = Db::getInstance()->numRows($RESULTAT_SQL);
|
|
|
|
if ($NOMBRELIGNE > 0)
|
|
{
|
|
echo "<br>";
|
|
echo "No de commande : ".$order_id;
|
|
echo "<br>";
|
|
$last_order_state = OrderHistory::getLastOrderState(intval($order_id));
|
|
echo "Dernier etat :".$last_order_state->id ;
|
|
echo "<br>";
|
|
if($event_type == '10')
|
|
{
|
|
|
|
echo "COMMANDE ENVOYEE";
|
|
echo "<br>";
|
|
if($last_order_state->id != _PS_OS_SHIPPING_ )
|
|
{
|
|
|
|
$SQL_SHIPPING = 'UPDATE '._DB_PREFIX_."orders SET shipping_number = '$id_colis'
|
|
WHERE id_order = '$order_id' ";
|
|
|
|
Db::getInstance()->Query($SQL_SHIPPING);
|
|
|
|
$SQL_SHIPPING = 'UPDATE '._DB_PREFIX_."order_carrier SET tracking_number = '$id_colis'
|
|
WHERE id_order = '$order_id' ";
|
|
|
|
Db::getInstance()->Query($SQL_SHIPPING);
|
|
|
|
|
|
$orderHistory = new OrderHistory();
|
|
$orderHistory->id_order = $order_id;
|
|
$orderHistory->changeIdOrderState(intval(_PS_OS_SHIPPING_), intval($orderHistory->id_order), true);
|
|
|
|
/* Antadis */
|
|
//$orderHistory->add();
|
|
$order = new Order((int) $order_id);
|
|
$carrier = new Carrier((int) $order->getIdOrderCarrier());
|
|
if($id_colis && $carrier->url)
|
|
{
|
|
$templateVars = array('{followup}' => str_replace('@', $id_colis, $carrier->url));
|
|
$orderHistory->addWithemail(true, $templateVars);
|
|
}
|
|
else
|
|
{
|
|
$orderHistory->addWithemail();
|
|
}
|
|
/* Antadis */
|
|
|
|
echo "<br>";
|
|
$last_order_state_shipping = OrderHistory::getLastOrderState(intval($order_id));
|
|
echo "Nouvel etat :".$last_order_state_shipping->id;
|
|
echo "<br>";
|
|
$nb_done ++;
|
|
}
|
|
else
|
|
{
|
|
echo "COMMANDE DONT LE STATUT EST DEJA OS SHIPPING"."<br>";
|
|
}
|
|
|
|
}
|
|
elseif($event_type == '20')
|
|
{
|
|
echo "COMMANDE LIVREE";
|
|
echo "<br>";
|
|
if($last_order_state->id != _PS_OS_DELIVERED_ )
|
|
{
|
|
echo "<br>";
|
|
|
|
$orderHistory = new OrderHistory();
|
|
$orderHistory->id_order = $order_id;
|
|
$orderHistory->changeIdOrderState(intval(_PS_OS_DELIVERED_), intval($orderHistory->id_order), true);
|
|
$orderHistory->add();
|
|
echo "<br>";
|
|
$last_order_state_delivered = OrderHistory::getLastOrderState(intval($order_id));
|
|
echo "Nouvel etat :".$last_order_state_delivered->id;
|
|
echo "<br>";
|
|
$nb_done ++;
|
|
|
|
}
|
|
else
|
|
{
|
|
echo "COMMANDE DONT LE STATUT EST DEJA OS DELIVERED"."<br>";
|
|
}
|
|
|
|
}
|
|
elseif($event_type == '30')
|
|
{
|
|
echo "COMMANDE ANNULEE";
|
|
echo "<br>";
|
|
if($last_order_state->id != _PS_OS_CANCELED_ )
|
|
{
|
|
$orderHistory = new OrderHistory();
|
|
$orderHistory->id_order = $order_id;
|
|
$orderHistory->changeIdOrderState(intval(_PS_OS_CANCELED_), intval($orderHistory->id_order));
|
|
$orderHistory->add();
|
|
echo "<br>";
|
|
$last_order_state_canceled = OrderHistory::getLastOrderState(intval($order_id));
|
|
echo "Nouvel etat :".$last_order_state_canceled->id;
|
|
echo "<br>";
|
|
$nb_done ++;
|
|
}
|
|
else
|
|
{
|
|
echo "COMMANDE DONT LE STATUT EST DEJA OS CANCELEDED"."<br>";
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
$log_statuts = $DATE.' | MAJ : '.$nb_done.' / '.$p_cnt.' records';
|
|
|
|
echo "Log : ".$log_statuts;
|
|
|
|
Logger::addLog($log_statuts, 1, 101, 'Logging object');
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|