Merge remote-tracking branch 'origin/ticket/r15365-logistic-reshipping'

This commit is contained in:
Michael RICOIS 2018-01-15 14:26:15 +01:00
commit d063c3ef40
3 changed files with 79 additions and 67 deletions

View File

@ -20,11 +20,12 @@ foreach(array_map(function($value) {
include _PS_ROOT_DIR_.'/modules/privatesales/Sale.php';
class AdminLogistics extends AdminTab {
class AdminLogistics extends AdminTab
{
public $_html = '';
private function stripaccents($str) {
private function stripaccents($str)
{
return preg_replace(
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);~i',
'$1',
@ -32,7 +33,8 @@ class AdminLogistics extends AdminTab {
);
}
private function isoreplace($str) {
private function isoreplace($str)
{
// ISO/CEI 646
return str_replace(array(
'Ç', 'ü', 'é', 'â', 'ä', 'à',
@ -84,41 +86,10 @@ class AdminLogistics extends AdminTab {
), $str);
}
private function printLabel($data, $mr=false) {
private function printLabel($data, $mr=false)
{
global $cookie;
//require dirname(__FILE__).'/libs/predis/autoload.php'; // Conflicts with Prestashop autoload
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/OptionInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/AbstractOption.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/Processor/CommandProcessingInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/PrefixableCommandInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/CommandInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/AbstractCommand.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/PrefixableCommand.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/PubSubPublish.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/SingleConnectionInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/AbstractConnection.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/StreamConnection.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionParametersInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionParameters.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionFactoryInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionFactory.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Profile/ServerProfileInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Profile/ServerProfile.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Profile/ServerVersion26.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientCluster.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientPrefix.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientExceptions.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientReplication.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientConnectionFactory.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientProfile.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientOptionsInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientOptions.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/BasicClientInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/ClientInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Client.php';
$redis = new Predis\Client();
if($mr){
@ -158,13 +129,16 @@ class AdminLogistics extends AdminTab {
return TRUE;
}
public function postProcess() {
public function postProcess()
{
global $cookie, $logistics_carriers;
// Delete number
if(( in_array((int)$cookie->profile, array(1,9,7,13,14)) )
&& ( $delete_number = Tools::getValue('delete_number') )) {
if($delete = (int) Tools::getValue('delete_laposte')) {
// Suppression LAPOSTE
if ($delete = (int) Tools::getValue('delete_soflexibilite')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'lapostews`
WHERE `id_order_detail` = '.$delete.'
@ -185,7 +159,9 @@ class AdminLogistics extends AdminTab {
AND `shipping_number` = "'.pSQL($delete_number).'"
');
}
} elseif($delete = (int) Tools::getValue('delete_exapaq')) {
}
// Suppression EXAPAQ
elseif ($delete = (int) Tools::getValue('delete_exapaq')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'exapaqws`
WHERE `id_order_detail` = '.$delete.'
@ -203,7 +179,9 @@ class AdminLogistics extends AdminTab {
AND `shipping_number` = "'.pSQL($delete_number).'"
');
}
} elseif($delete = (int) Tools::getValue('delete_mondialrelay')) {
}
// Suppression MONDIAL RELAY
elseif ($delete = (int) Tools::getValue('delete_mondialrelay')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'mondialrelay_parcel`
WHERE `id_order_detail` = '.$delete.'
@ -222,7 +200,28 @@ class AdminLogistics extends AdminTab {
');
}
}
// Suppression PHILEA
elseif ($delete = (int) Tools::getValue('delete_philea')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'philea_parcel`
WHERE `id_order_detail` = '.$delete.'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
if(!Db::getInstance()->getRow('
SELECT `shipping_number`
FROM `'._DB_PREFIX_.'philea_parcel`
WHERE `shipping_number` = "'.pSQL($delete_number).'"
')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) Tools::getValue('id_order').'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
}
}
// Pour les commandes et les articles mise à jours en commande non envoyé, simplement payé
$id_order_details = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order_detail`
@ -273,9 +272,9 @@ class AdminLogistics extends AdminTab {
) {
$weight = 0.24;
$order = new Order((int) $id_order);
if(Validate::isLoadedObject($order)) {
$parcel_carrier == 'laposte'? $weight = 0.24: TRUE;
if($parcel_carrier == "laposte" || $parcel_carrier == "mondialrelay") {
if (Validate::isLoadedObject($order)) {
$parcel_carrier == 'laposte' ? $weight = 0.24 : true;
if ($parcel_carrier == "laposte" || $parcel_carrier == "mondialrelay") {
$result = $logistics_carriers[$parcel_carrier]->registerParcel($order, $products, $weight);
if($result[0] != '') {
$this->_html .= $result[0];
@ -301,10 +300,10 @@ class AdminLogistics extends AdminTab {
$this->_html .= '<p class="conf">'.$this->l('Registration complete, label sent to printer').'</p><br />';
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175'
&& $_SERVER['REMOTE_ADDR'] != '78.226.56.137'
&& $_SERVER['REMOTE_ADDR'] != '88.163.22.223'
&& $_SERVER['REMOTE_ADDR'] != '37.160.139.229'
&& substr($_SERVER['REMOTE_ADDR'], 0, 2) != '37') {
&& $_SERVER['REMOTE_ADDR'] != '78.226.56.137'
&& $_SERVER['REMOTE_ADDR'] != '88.163.22.223'
&& $_SERVER['REMOTE_ADDR'] != '37.160.139.229'
&& substr($_SERVER['REMOTE_ADDR'], 0, 2) != '37') {
$products_names = array();
foreach(Db::getInstance()->ExecuteS('
@ -819,9 +818,9 @@ class AdminLogistics extends AdminTab {
<td>\' + loaded.logs[i].shipping_number + \'</td>\
<td>\' + ((loaded.logs[i].carrier == "laposte" || loaded.logs[i].carrier == "mondialrelay") ? carriers[loaded.logs[i].carrier] : loaded.logs[i].carrier) + \'</td>\
'.(( in_array((int)$cookie->profile, array(1,9,7,13,14)) ) ?
'\' + ((loaded.logs[i].carrier == "laposte" || loaded.logs[i].carrier == "mondialrelay") ?\'<td><a href="/adm/index.php?tab=AdminLogistics&token='.Tools::getAdminTokenLite('AdminLogistics').'&id_order=\' + loaded.order.id + \'&delete_\' + loaded.logs[i].carrier + \'=\' + loaded.logs[i].id_order_detail + \'&delete_number=\' + loaded.logs[i].shipping_number + \'">x</a></td>': '').'\':"") +\'\
'\' + \'<td><a title="Set article as not sent" href="/adm/index.php?tab=AdminLogistics&token='.Tools::getAdminTokenLite('AdminLogistics').'&id_order=\' + loaded.order.id + \'&delete_\' + ((loaded.logs[i].philea == 1) ? \'philea\' : loaded.logs[i].carrier) + \'=\' + loaded.logs[i].id_order_detail + \'&delete_number=\' + loaded.logs[i].shipping_number + \'">x</a></td>': '').'\' +\'\
'.(( in_array((int)$cookie->profile, array(1,9,7,13,14)) ) ?
'\' + ((loaded.logs[i].carrier == "laposte" || loaded.logs[i].carrier == "mondialrelay") ?\'<td><a title="Re print" class="reprint ui-icon ui-icon-arrowthickstop-1-s" data-product="\' + loaded.logs[i].product_name.replace(" - ", "<br />") + \'" data-weight="\' + loaded.logs[i].weight + \'" data-ref="\' + loaded.logs[i].product_reference + \'" data-id_order="\' + loaded.order.id + \'" data-carrier="\' + loaded.logs[i].carrier + \'" data-id_order_detail="\' + loaded.logs[i].id_order_detail + \'">+</a></td>': '').'\':"") +\'\
'\' + \'<td><a title="Re print" class="reprint ui-icon ui-icon-arrowthickstop-1-s" data-product="\' + loaded.logs[i].product_name.replace(" - ", "<br />") + \'" data-weight="\' + loaded.logs[i].weight + \'" data-ref="\' + loaded.logs[i].product_reference + \'" data-id_order="\' + loaded.order.id + \'" data-carrier="\' + loaded.logs[i].carrier + \'" data-id_order_detail="\' + loaded.logs[i].id_order_detail + \'">+</a></td>': '').'\' +\'\
</tr>\';
}

View File

@ -406,60 +406,70 @@ if(($id_order = (int) Tools::getValue('id_order'))
if(count($id_order_details) > 0) {
$logs = array();
// Send by LAPOSTE
if($l = Db::getInstance()->ExecuteS('
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, e.`firstname`, e.`lastname`, "laposte" AS `carrier`
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`,
e.`firstname`, e.`lastname`, "laposte" as carrier, "0" as philea
FROM `'._DB_PREFIX_.'lapostews` l
LEFT JOIN `'._DB_PREFIX_.'employee` e ON l.`id_employee` = e.`id_employee`
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail`
LEFT JOIN `ps_carrier` c ON c.`id_carrier` = o.`id_carrier`
WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).')
AND l.`quantity` > 0
ORDER BY l.`date_add` DESC
')) {
$logs = array_merge($logs, $l);
}
// Send by EXAPAQ
if($l = Db::getInstance()->ExecuteS('
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, e.`firstname`, e.`lastname`, "exapaq" AS `carrier`
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`,
e.`firstname`, e.`lastname`, "exapaq" as carrier, "0" as philea
FROM `'._DB_PREFIX_.'exapaqws` l
LEFT JOIN `'._DB_PREFIX_.'employee` e ON l.`id_employee` = e.`id_employee`
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'carrier` c ON c.`id_carrier` = o.`id_carrier`
WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).')
AND l.`quantity` > 0
ORDER BY l.`date_add` DESC
')) {
$logs = array_merge($logs, $l);
}
/*
* @Override MondialRelay
*/
// Send by MONDIAL RELAY
if($l = Db::getInstance()->ExecuteS('
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, e.`firstname`, e.`lastname`, "mondialrelay" AS `carrier`
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`,
e.`firstname`, e.`lastname`, "mondialrelay" as carrier, "0" as philea
FROM `'._DB_PREFIX_.'mondialrelay_parcel` l
LEFT JOIN `'._DB_PREFIX_.'employee` e ON l.`id_employee` = e.`id_employee`
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail`
LEFT JOIN `ps_carrier` c ON c.`id_carrier` = o.`id_carrier`
WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).')
AND l.`quantity` > 0
ORDER BY l.`date_add` DESC
')) {
$logs = array_merge($logs, $l);
}
/*
* @Override Dropshipping
*/
// Send by DROPSHIPPING
if($l = Db::getInstance()->ExecuteS('
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, "Dropshipping" as firstname
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`,
"Dropshipping" as firstname, "0" as philea
FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` l
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'carrier` c ON c.`id_carrier` = o.`id_carrier`
WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).')
AND l.`quantity` > 0
ORDER BY l.`date_add` DESC
')) {
$logs = array_merge($logs, $l);
}
/*
* @Override Philea
*/
// Send by PHILEA
if($l = Db::getInstance()->ExecuteS('
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, "Philea" as firstname, c.`name` as carrier
SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, "Philea" as firstname,
(CASE c.`external_module_name` WHEN "soflexibilite" THEN "laposte" ELSE c.`external_module_name` END) as carrier,
"1" as philea
FROM `'._DB_PREFIX_.'philea_parcel` l
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order`

View File

@ -623,7 +623,8 @@ $laposte_formats = array(
);
class LaposteCarrier {
class LaposteCarrier
{
public $displayName = 'La Poste';
public function l($string, $specific = false, $id_lang = null) {
@ -658,7 +659,8 @@ class LaposteCarrier {
);
}
public function registerParcel($order, $products, $weight) {
public function registerParcel($order, $products, $weight)
{
global $cookie;
$html = '';
@ -734,7 +736,8 @@ class LaposteCarrier {
return array($html, $result);
}
public function renderLabel($order, $weight, $shipping_data) {
public function renderLabel($order, $weight, $shipping_data)
{
global $cookie, $laposte_formats;
/**