Update from logistics module

This commit is contained in:
Michael RICOIS 2018-02-06 09:31:12 +01:00
parent 60cef82038
commit 42b5f95c1f
3 changed files with 1770 additions and 42 deletions

View File

@ -623,7 +623,8 @@ $laposte_formats = array(
); );
class LaposteCarrier { class LaposteCarrier
{
public $displayName = 'La Poste'; public $displayName = 'La Poste';
public function l($string, $specific = false, $id_lang = null) { 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; global $cookie;
$html = ''; $html = '';
@ -734,7 +736,8 @@ class LaposteCarrier {
return array($html, $result); return array($html, $result);
} }
public function renderLabel($order, $weight, $shipping_data) { public function renderLabel($order, $weight, $shipping_data)
{
global $cookie, $laposte_formats; global $cookie, $laposte_formats;
/** /**
@ -1548,58 +1551,126 @@ class LaposteCarrier {
$history = new OrderHistory(); $history = new OrderHistory();
$history->id_order = (int) $order->id; $history->id_order = (int) $order->id;
$fully_sent = TRUE; $fully_sent = FALSE;
$products_sent = array(); $products_sent = array();
$to_send = array();
$shipping_numbers = array(); $order_details = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order->id.'
') as $row) {
$order_details[] = (int) $row['id_order_detail'];
}
foreach(Db::getInstance()->ExecuteS(' foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF( SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF( (d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded` d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0 ) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`, s.`shipping_number` ) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'lapostews` s LEFT OUTER JOIN `'._DB_PREFIX_.'lapostews` s
ON s.`id_order_detail` = d.`id_order_detail` ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.' WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail` GROUP BY d.`id_order_detail`
') as $quantity_remain) { ') as $quantity_remain) {
if($quantity_remain['shipping_number']) { if((int) $quantity_remain['remain'] == 0) {
$shipping_numbers[] = pSQL($quantity_remain['shipping_number']); $products_sent[] = (int) $quantity_remain['id_order_detail'];
}
if((int) $quantity_remain['remain'] > 0) {
$fully_sent = FALSE;
$to_send[] = (int) $quantity_remain['id_order_detail'];
} }
} }
$_to_send = array(); foreach(Db::getInstance()->ExecuteS('
foreach($to_send as $p) { SELECT d.`id_order_detail`, IF(
$id_sale = (int) Db::getInstance()->getValue(' (d.`product_quantity` - IF(
SELECT `id_sale` d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
FROM `'._DB_PREFIX_.'product_ps_cache` ) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
WHERE `id_product` = ( ) AS `remain`
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail` d
FROM `'._DB_PREFIX_.'order_detail` LEFT OUTER JOIN `'._DB_PREFIX_.'exapaqws` s
WHERE `id_order` = '.(int) $order->id.' ON s.`id_order_detail` = d.`id_order_detail`
AND `id_order_detail` = '.(int) $p.' WHERE d.`id_order` = '.(int) $order->id.'
) GROUP BY d.`id_order_detail`
'); ') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
if(!Db::getInstance()->getValue(' foreach(Db::getInstance()->ExecuteS('
SELECT `id_order` SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'mondialrelay_parcel` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'philea_parcel` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
$remaining = array();
foreach($order_details as $d) {
if(!in_array($d, $products_sent)) {
$remaining[] = (int) $d;
}
}
if(count($remaining) == 0) {
$fully_sent = TRUE;
} else {
$id_sales = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT c.`id_sale`
FROM `'._DB_PREFIX_.'product_ps_cache` c
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON c.`id_product` = d.`product_id`
WHERE d.`id_order_detail` IN ('.implode(', ', $remaining).')
') as $row) {
$id_sales[] = (int) $row['id_sale'];
}
$sent_sales = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_sale`
FROM `'._DB_PREFIX_.'shipping_history` FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) $order->id.' WHERE `id_order` = '.(int) $order->id.'
AND `id_sale` = '.(int) $id_sale.' AND `id_sale` IN ('.implode(', ', $id_sales).')
AND `shipping_number` NOT IN ("'.implode('", "', $shipping_numbers).'") ') as $row) {
')) { $sent_sales[] = (int) $row['id_sale'];
$_to_send[] = $p;
} }
}
if(count($_to_send) === 0) { $remaining = array();
$fully_sent = TRUE; foreach($id_sales as $s) {
if(!in_array($s, $sent_sales)) {
$remaining[] = (int) $s;
break;
}
}
$fully_sent = (count($remaining) == 0);
} }
//mail('perron@antadis.com', 'test logistics', (int) $order->id); //mail('perron@antadis.com', 'test logistics', (int) $order->id);

View File

@ -382,14 +382,18 @@ class Parcel {
'exp_phone' => Configuration::get('LAPOSTEWS_EXP_PHONE'), 'exp_phone' => Configuration::get('LAPOSTEWS_EXP_PHONE'),
); );
$c = new SoapClient( $c = false;
'https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl', try {
array( $c = new SoapClient(
'trace' => 0, 'https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl',
'exceptions' => 1, array(
'cache_wsdl' => 0? WSDL_CACHE_MEMORY: WSDL_CACHE_NONE, 'trace' => 0,
) 'exceptions' => 1,
); 'cache_wsdl' => 0 ? WSDL_CACHE_MEMORY: WSDL_CACHE_NONE,
)
);
} catch (Exception $e) {}
try { try {
$exp_country = new Country((int) $carrier_config['exp_country']); $exp_country = new Country((int) $carrier_config['exp_country']);
if(in_array($exp_country->iso_code, array('GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) { if(in_array($exp_country->iso_code, array('GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {

File diff suppressed because it is too large Load Diff