diff --git a/modules/logistics/AdminLogistics.php b/modules/logistics/AdminLogistics.php index 5a7ccda0..dfd3f176 100644 --- a/modules/logistics/AdminLogistics.php +++ b/modules/logistics/AdminLogistics.php @@ -274,7 +274,7 @@ class AdminLogistics extends AdminTab $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 ($parcel_carrier == 'laposte' || $parcel_carrier == 'mondialrelay') { $result = $logistics_carriers[$parcel_carrier]->registerParcel($order, $products, $weight); if($result[0] != '') { $this->_html .= $result[0]; diff --git a/modules/logistics/ajax.php b/modules/logistics/ajax.php index dc909a58..ffe20b7a 100644 --- a/modules/logistics/ajax.php +++ b/modules/logistics/ajax.php @@ -119,106 +119,9 @@ if(($id_order = (int) Tools::getValue('id_order')) $invoice_address = new Address($order->id_address_invoice); $delivery_address = new Address($order->id_address_delivery); - - /*if($delivery_address->id_country == 8) { - $replace_tests = array( - '-S-' => ' SUR ', - '-SS-' => ' SOUS ', - ' ST-' => ' SAINT ', - '-ST ' => ' SAINT ', - '-ST-' => ' SAINT ', - ' STE-' => ' SAINTE ', - '-STE ' => ' SAINTE ', - '-STE ' => ' SAINTE ', - ' MT-' => ' MONT ', - '-MT ' => ' MONT ', - '-MT-' => ' MONT ', - ' BG-' => ' BOURG ', - '-BG ' => ' BOURG ', - '-BG-' => ' BOURG ', - ' GD-' => ' GRAND ', - '-GD ' => ' GRAND ', - '-GD-' => ' GRAND ', - ' GDE-' => ' GRANDE ', - '-GDE ' => ' GRANDE ', - '-GDE-' => ' GRANDE ', - ' MTS-' => ' MONTS ', - '-MTS ' => ' MONTS ', - '-MTS-' => ' MONTS ', - ' VX-' => ' VIEUX ', - '-VX ' => ' VIEUX ', - '-VX-' => ' VIEUX ', - ' HT-' => ' HAUT ', - '-HT ' => ' HAUT ', - '-HT-' => ' HAUT ', - ' BS-' => ' BAS ', - '-BS ' => ' BAS ', - '-BS-' => ' BAS ', - ' S ' => ' SUR ', - ' SS ' => ' SOUS ', - ' ST ' => ' SAINT ', - ' STE ' => ' SAINTE ', - ' MT ' => ' MONT ', - ' BG ' => ' BOURG ', - ' GD ' => ' GRAND ', - ' GDE ' => ' GRANDE ', - ' MTS ' => ' MONTS ', - ' VX ' => ' VIEUX ', - ' HT ' => ' HAUT ', - ' BS ' => ' BAS ', - ' ST. ' => ' SAINT ', - ); - - $cities = array(); - foreach(Db::getInstance()->ExecuteS(' - SELECT `city` - FROM `'._DB_PREFIX_.'france_postcode` - WHERE `postcode` = "'.pSQL(trim($delivery_address->postcode)).'" - ') as $row) { - $cities[] = $row['city']; - } - $found = FALSE; - if($cities) { - foreach($cities as $city) { - if(str_replace(array('\\', '-', '_', ' ', '/', '\'', '"', '«', '»', '’', ' ', '.', ',',), '', strtolower(trim(stripaccents($city)))) == str_replace(array('\\', '-', '_', ' ', '/', '\'', '"', '«', '»', '’', ' ', '.', ',',), '', strtolower(trim(stripaccents(preg_replace('/ C(I|E)DEX(.*)$/i', '', $delivery_address->city)))))) { - $found = TRUE; - } - } - } - - if(!$found) { - foreach($cities as $city) { - $clean_city = str_replace(array('\\', '-', '_', ' ', '/', '\'', '"', '«', '»', '’', ' ', '.', ',',), '', strtolower(trim(stripaccents($city)))); - $clean_customer_city = str_replace(array('\\', '-', '_', ' ', '/', '\'', '"', '«', '»', '’', ' ', '.', ',',), '', strtolower(trim(str_ireplace('/', ' SUR ', str_ireplace(' S/', ' SUR ', str_ireplace(array_keys($replace_tests), array_values($replace_tests), stripaccents(' '.preg_replace('/ C(I|E)DEX(.*)$/i', '', $delivery_address->city).' '))))))); - if($clean_city === $clean_customer_city - || $clean_city === 'le'.$clean_customer_city - || $clean_city === 'la'.$clean_customer_city - || $clean_city === 'les'.$clean_customer_city - || $clean_city === 'l'.$clean_customer_city - || 'le'.$clean_city === $clean_customer_city - || 'la'.$clean_city === $clean_customer_city - || 'les'.$clean_city === $clean_customer_city - || 'l'.$clean_city === $clean_customer_city) { - $found = TRUE; - } - } - } - $france_address_error = !$found; - $france_address_suggestions = array(); - - if($france_address_error) { - $france_address_suggestions = Db::getInstance()->ExecuteS(' - SELECT `postcode`, `city` - FROM `'._DB_PREFIX_.'france_postcode` - WHERE `postcode` = "'.pSQL($delivery_address->postcode).'" - OR `city` = "'.pSQL($delivery_address->city).'" - GROUP BY `postcode`, `city` - '); - } - } else {*/ - $france_address_error = FALSE; - $france_address_suggestions = array(); - /*}*/ + + $france_address_error = FALSE; + $france_address_suggestions = array(); $id_order_details = array(); @@ -227,41 +130,39 @@ if(($id_order = (int) Tools::getValue('id_order')) $link = new Link(2); $products = array(); foreach($order->getProductsDetail() as $p) { - $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' + // --- Get quantity sent + // LaPoste + $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'lapostews` WHERE `id_order_detail` = '.(int) $p['id_order_detail'].' '); + // Exapaq $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'exapaqws` WHERE `id_order_detail` = '.(int) $p['id_order_detail'].' '); - /** - * @Override MondialRelay - */ + // MondialRelay $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'mondialrelay_parcel` WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . ' '); - /** - * @Override Philea - */ + // Philea $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'philea_parcel` WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . ' '); - /** - * @Override Dropshipping - */ + // DropShipping $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . ' '); + // Image $p['id_image'] = 0; if((int) $p['product_attribute_id'] != 0) { @@ -287,21 +188,6 @@ if(($id_order = (int) Tools::getValue('id_order')) $p['image'] = '//'.$link->getImageLink('image', $p['product_id'].'-'.$p['id_image'], 'home'); - /*$shipping = Db::getInstance()->getRow(' - SELECT s.`id_shipping`, s.`id_sale` - FROM `'._DB_PREFIX_.'privatesale_shipping_sale` s - LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c - ON c.`id_sale` = s.`id_sale` - WHERE c.`id_product` = '.(int) $p['product_id'].' - '); - - if(!$shipping) { - $p['id_shipping'] = 1; // PSS - $p['id_sale'] = 999999; - } else { - $p['id_shipping'] = $shipping['id_shipping']; - $p['id_sale'] = $shipping['id_sale']; - }*/ $p['id_shipping'] = 1; $p['id_sale'] = (int) Db::getInstance()->getValue(' SELECT `id_sale` @@ -315,7 +201,7 @@ if(($id_order = (int) Tools::getValue('id_order')) WHERE `id_product` = '.(int) $p['product_id'].' AND id_order = '.(int)$id_order ); - if(!isset($sales_carriers[(int) $p['id_sale']])) { + if (!isset($sales_carriers[(int) $p['id_sale']])) { $sales_carriers[(int) $p['id_sale']] = array(); foreach(Db::getInstance()->ExecuteS(' SELECT `id_carrier` @@ -327,10 +213,22 @@ if(($id_order = (int) Tools::getValue('id_order')) } $p['carriers'] = $sales_carriers[(int) $p['id_sale']]; - - $p['location'] = isset($locations[(int) $p['product_id'].'-'.(int) $p['product_attribute_id']])? $locations[(int) $p['product_id'].'-'.(int) $p['product_attribute_id']]: ''; - + $p['location'] = isset($locations[(int) $p['product_id'].'-'.(int) $p['product_attribute_id']]) ? + $locations[(int) $p['product_id'].'-'.(int) $p['product_attribute_id']]: ''; + + // --- Get Shipping Numbers $shipping_numbers = array(); + // Philea + foreach(Db::getInstance()->ExecuteS(' + SELECT l.`shipping_number` + 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_.'order_history` h ON (h.`id_order` = d.`id_order`) + WHERE h.`id_order` = '.(int) $order->id.' + ') as $row) { + $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; + } + // LaPoste foreach(Db::getInstance()->ExecuteS(' SELECT l.`shipping_number` FROM `'._DB_PREFIX_.'lapostews` l @@ -340,6 +238,7 @@ if(($id_order = (int) Tools::getValue('id_order')) ') as $row) { $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; } + // Exapaq foreach(Db::getInstance()->ExecuteS(' SELECT e.`shipping_number` FROM `'._DB_PREFIX_.'exapaqws` e @@ -349,9 +248,7 @@ if(($id_order = (int) Tools::getValue('id_order')) ') as $row) { $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; } - /* - * @Override MondialRelay - */ + // MondialRelay foreach(Db::getInstance()->ExecuteS(' SELECT l.`shipping_number` FROM `'._DB_PREFIX_.'mondialrelay_parcel` l @@ -361,28 +258,16 @@ if(($id_order = (int) Tools::getValue('id_order')) ') as $row) { $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; } - /* - * @Override Philea - */ - foreach(Db::getInstance()->ExecuteS(' - SELECT l.`shipping_number` - 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_.'order_history` h ON (h.`id_order` = d.`id_order`) - WHERE h.`id_order` = '.(int) $order->id.' - ') as $row) { - $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; - } - if(((int) $p['product_quantity_sent'] === 0) - && Db::getInstance()->getRow(' + if(((int) $p['product_quantity_sent'] === 0) && Db::getInstance()->getRow(' SELECT h.`id_sale` FROM `'._DB_PREFIX_.'shipping_history` h - WHERE h.`id_sale` = '.((int) $p['id_sale'] === 999999? 0: (int) $p['id_sale']).' + WHERE h.`id_sale` = '.((int) $p['id_sale'] === 999999 ? 0: (int) $p['id_sale']).' AND h.`id_order` = '.(int) $order->id.' '.(count($shipping_numbers) > 0? 'AND h.`shipping_number` NOT IN ('.implode(', ', $shipping_numbers).')': '').' ')) { - $p['product_quantity_sent'] = $p['product_quantity'] - ($p['product_quantity_return'] > 0? $p['product_quantity_return']: $p['product_quantity_refunded']); + $p['product_quantity_sent'] = $p['product_quantity'] - ( $p['product_quantity_return'] > 0 ? + $p['product_quantity_return']: $p['product_quantity_refunded'] ); } $products[] = $p; @@ -406,67 +291,8 @@ 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, "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, "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); - } - - // 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, "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); - } - - // Send by DROPSHIPPING - if($l = Db::getInstance()->ExecuteS(' - 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); - } - - // Send by PHILEA - if($l = Db::getInstance()->ExecuteS(' + // Send by PHILEA + if ($l = Db::getInstance()->ExecuteS(' 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 @@ -478,8 +304,72 @@ if(($id_order = (int) Tools::getValue('id_order')) AND l.`quantity` > 0 ORDER BY l.`date_add` DESC ')) { + $logs = array_merge($logs, $l); + } + + // 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, "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 `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` + 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, "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_.'orders` o ON o.`id_order` = d.`id_order` + 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); + } + + // 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, "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 `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` + 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 DROPSHIPPING + if ($l = Db::getInstance()->ExecuteS(' + 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_.'orders` o ON o.`id_order` = d.`id_order` + 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); + } + } else { $logs = array(); }