chr(2).'m'.' 1911S2611800050P080P040{SHIPPING_NUMBER_C25I} 131110011200180{SHIPPING_NUMBER} 1X1100009400050b0480015000010001 1X1100005500050b0480035000010001 1X1100004100050b0510009000010001 1X1100002940050b0510009000010001 1X1100003450585b0200011000010001 1X1100008370050l04800001 1X1100004500050l05100001 1X1100003370050l05100001 1X1100004050585l02000001 1X1100004100210l00010090 1X1100004100350l00010090 1X1100002940210l00010090 1X1100002940350l00010090 1X1100009400051P001000110870525 1X1100009400525P001000110870051 1911S2410500065P010P010{EXP_COMPANY} 1911S2310200065P008P008{EXP_ADDR1} 1911S2309900065P008P008{EXP_ADDR2} 1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY} 1911S2408550065P010P010Destinataire 1911S2407940065P010P010{DEST_ADDR1} 1911S2307640065P006P006{DEST_ADDR2} 1911S2307370065P006P006{DEST_ADDR3} 1911S2307100065P006P006{DEST_ADDR4} 1911S2306830065P006P006{DEST_ADDR5} 1911S2406440065P010P010{DEST_POSTCODE} 1911S2306440180P010P010{DEST_CITY} 1911S2306060065P010P010{DEST_PHONE} 1911S2305700065P010P010{DEST_OTHER} 1911S2410100570P025P014{SHIPPING_1} / 1911S2410180700P020P012{SHIPPING_2} 1911S2409200570P025P014AG {SHIPPING_3} 1911S2408400570P020P012N {SHIPPING_4} - A5 1911S2408400710P020P012{SHIPPING_5} A2 1911S2407600570P020P012T {SHIPPING_6} 1911S2406700570P025P014{SHIPPING_7} 1911S2406750850P020P0121/1 1911S2405700570P025P014{SHIPPING_8} 1911S2404650065P007P006N'.chr(248).' exp'.chr(130).'dition 1911S2404650220P007P006Date d\'envoi 1911S2404650360P007P006Agence de collecte 1911S2304220080P007P007{EXPEDITION_NUMBER} 1911S2304220220P007P007{DATE} 1911S2304220420P007P007{AGENCY_CODE} 1911S2404180595P009P009A Encaisser 1911S2403630661P010P0100 '.chr(255).' 1Y0000003240820MONDIALR 1911S2403500080P007P006Poids (kg) 1911S2403500225P007P006Volume (L) 1911S2403500410P007P006N'.chr(248).' Colis 1911S2303060085P007P007{WEIGHT} 1911S2303060265P007P007{VOLUME} 1911S2303060430P007P0071/1 1911S2302400050P007P007{INSTRUCTIONS} '.chr(2).'n ', 'EN' => chr(2).'m'.' 1911S2611800050P080P040{SHIPPING_NUMBER_C25I} 131110011200180{SHIPPING_NUMBER} 1X1100009400050b0480015000010001 1X1100005500050b0480035000010001 1X1100004100050b0510009000010001 1X1100002940050b0510009000010001 1X1100003450585b0200011000010001 1X1100008370050l04800001 1X1100004500050l05100001 1X1100003370050l05100001 1X1100004050585l02000001 1X1100004100210l00010090 1X1100004100350l00010090 1X1100002940210l00010090 1X1100002940350l00010090 1X1100009400051P001000110870525 1X1100009400525P001000110870051 1911S2410500065P010P010{EXP_COMPANY} 1911S2310200065P008P008{EXP_ADDR1} 1911S2309900065P008P008{EXP_ADDR2} 1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY} 1911S2408550065P010P010Consignee 1911S2407940065P010P010{DEST_ADDR1} 1911S2307640065P006P006{DEST_ADDR2} 1911S2307370065P006P006{DEST_ADDR3} 1911S2307100065P006P006{DEST_ADDR4} 1911S2306830065P006P006{DEST_ADDR5} 1911S2406440065P010P010{DEST_POSTCODE} 1911S2306440180P010P010{DEST_CITY} 1911S2306060065P010P010{DEST_PHONE} 1911S2305700065P010P010{DEST_OTHER} 1911S2410100570P025P014{SHIPPING_1} / 1911S2410180700P020P012{SHIPPING_2} 1911S2409200570P025P014AG {SHIPPING_3} 1911S2408400570P020P012N {SHIPPING_4} - A5 1911S2408400710P020P012{SHIPPING_5} A2 1911S2407600570P020P012T {SHIPPING_6} 1911S2406700570P025P014{SHIPPING_7} 1911S2406750850P020P0121/1 1911S2405700570P025P014{SHIPPING_8} 1911S2404650065P007P006No. Shipment 1911S2404650220P007P006Sending Date 1911S2404650360P007P006Connection Agency 1911S2304220080P007P007{EXPEDITION_NUMBER} 1911S2304220220P007P007{DATE} 1911S2304220420P007P007{AGENCY_CODE} 1911S2404180595P009P009C.O.D. 1911S2403630661P010P0100 '.chr(255).' 1Y0000003240820MONDIALR 1911S2403500080P007P006Weight (kg) 1911S2403500225P007P006Volume (L) 1911S2403500410P007P006No. Parcel 1911S2303060085P007P007{WEIGHT} 1911S2303060265P007P007{VOLUME} 1911S2303060430P007P0071/1 1911S2302400050P007P007{INSTRUCTIONS} '.chr(2).'n ', 'ES' => chr(2).'m'.' 1911S2611800050P080P040{SHIPPING_NUMBER_C25I} 131110011200180{SHIPPING_NUMBER} 1X1100009400050b0480015000010001 1X1100005500050b0480035000010001 1X1100004100050b0510009000010001 1X1100002940050b0510009000010001 1X1100003450585b0200011000010001 1X1100008370050l04800001 1X1100004500050l05100001 1X1100003370050l05100001 1X1100004050585l02000001 1X1100004100210l00010090 1X1100004100350l00010090 1X1100002940210l00010090 1X1100002940350l00010090 1X1100009400051P001000110870525 1X1100009400525P001000110870051 1911S2410500065P010P010{EXP_COMPANY} 1911S2310200065P008P008{EXP_ADDR1} 1911S2309900065P008P008{EXP_ADDR2} 1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY} 1911S2408550065P010P010Destinario 1911S2407940065P010P010{DEST_ADDR1} 1911S2307640065P006P006{DEST_ADDR2} 1911S2307370065P006P006{DEST_ADDR3} 1911S2307100065P006P006{DEST_ADDR4} 1911S2306830065P006P006{DEST_ADDR5} 1911S2406440065P010P010{DEST_POSTCODE} 1911S2306440180P010P010{DEST_CITY} 1911S2306060065P010P010{DEST_PHONE} 1911S2305700065P010P010{DEST_OTHER} 1911S2410100570P025P014{SHIPPING_1} / 1911S2410180700P020P012{SHIPPING_2} 1911S2409200570P025P014AG {SHIPPING_3} 1911S2408400570P020P012N {SHIPPING_4} - A5 1911S2408400710P020P012{SHIPPING_5} A2 1911S2407600570P020P012T {SHIPPING_6} 1911S2406700570P025P014{SHIPPING_7} 1911S2406750850P020P0121/1 1911S2405700570P025P014{SHIPPING_8} 1911S2404650065P007P006N'.chr(248).' d\'exp'.chr(130).'dicion 1911S2404650220P007P006Fetcha de envio 1911S2404650360P007P006Agencia de Cobros 1911S2304220080P007P007{EXPEDITION_NUMBER} 1911S2304220220P007P007{DATE} 1911S2304220420P007P007{AGENCY_CODE} 1911S2404180595P009P009A Cobrar 1911S2403630661P010P0100 '.chr(255).' 1Y0000003240820MONDIALR 1911S2403500080P007P006Peso (kg) 1911S2403500225P007P006Volumen (L) 1911S2403500410P007P006N'.chr(248).' Paquete 1911S2303060085P007P007{WEIGHT} 1911S2303060265P007P007{VOLUME} 1911S2303060430P007P0071/1 1911S2302400050P007P007{INSTRUCTIONS} '.chr(2).'n ', ); class MondialrelayCarrier { public $displayName = 'Mondial Relay'; public function checkavailability() { return TRUE; } public function __toString() { return $this->displayName; } 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', htmlentities($str, ENT_QUOTES, 'UTF-8') ); } public function renderLabel($order, $weight, $shipping_data) { global $cookie, $mondialrelay_formats; $agencies = array( '0637' => 'BRIVE', '0606' => 'BORDEAUX', '0655' => 'CAEN', '0676' => 'CLERMONT-F', '0221' => 'CHAMBERY', '0603' => 'AJACCIO', '0677' => 'DIJON', '0662' => 'HEM', '0688' => 'ST OUEN', '0254' => 'LIEUSAINT', '0300' => 'LILLE', '0715' => 'LYON', '0648' => 'MARSEILLE', '0717' => 'METZ', '0718' => 'MONTPELLIE', '0719' => 'NANTES', '0301' => 'NICE', '0720' => 'MER', '0511' => 'REIMS', '0722' => 'RENNES', '0729' => 'ROUEN', '0737' => 'STRASBOURG', '0743' => 'TOULOUSE', '0749' => 'ORLEANS', '0930' => 'MONTREUIL', '0265' => 'VALENCE', '0975' => 'DOM TOM', '3010' => 'PORTUGAL', '3210' => 'ASM PT', '4010' => 'SPAIN', '4210' => 'ASM ES', '5010' => 'BELGIUM', '5199' => 'MONTREUIL', '5210' => 'BELGIQUE', '5310' => 'BPOST BE', '6610' => 'HERMES DE', '6620' => 'HERMES IT', '6630' => 'HERMES AT', '6640' => 'HERMES UK', '7210' => 'TNT NL', '8210' => 'DINTEC LU', ); $exp_company = Configuration::get('MONDIALRELAY_EXP_COMPANY'); $exp_address1 = Configuration::get('MONDIALRELAY_EXP_ADDR1'); $exp_address2 = Configuration::get('MONDIALRELAY_EXP_ADDR2'); $exp_postal = Configuration::get('MONDIALRELAY_EXP_POSTALCODE'); $exp_city = Configuration::get('MONDIALRELAY_EXP_CITY'); $exp_country = Configuration::get('MONDIALRELAY_EXP_COUNTRY'); $delivery_address = new Address((int) $order->id_address_delivery); if(!Validate::isLoadedObject($delivery_address)) { return FALSE; } $delivery_infos = Db::getInstance()->getRow(' SELECT s.*, m.`dlv_mode` FROM `'._DB_PREFIX_.'mr_selected` s LEFT JOIN `'._DB_PREFIX_.'mr_method` m ON s.`id_method` = m.`id_mr_method` WHERE s.`id_order` = '.(int) $order->id.' '); // Hack 5 numbers relay num if (isset($delivery_infos['MR_Selected_Num']) && $delivery_infos['MR_Selected_Num']) $delivery_infos['MR_Selected_Num'] = substr($delivery_infos['MR_Selected_Num'], -5); if(!$delivery_infos || in_array($delivery_infos['dlv_mode'], array('LDS', 'LD1', 'HOM'))) { $mode = $delivery_infos? $delivery_infos['dlv_mode']: 'LD1'; $shipping = array( $delivery_address->firstname.' '.$delivery_address->lastname, $delivery_address->company, $delivery_address->address1, $delivery_address->address2, $delivery_address->postcode, $delivery_address->city, '', empty($delivery_address->phone)? $delivery_address->phone_mobile: $delivery_address->phone, trim(str_replace('|', ' ', $delivery_address->other)), ); $dest_country = $delivery_address->id_country; } else { $mr_relais = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_relais` WHERE 1 AND `direction` = "'.pSQL($delivery_infos['MR_Selected_Num']).'" AND `prpay` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'" '); $mode = $delivery_infos['dlv_mode']; if($mode == '24R') { if($mr_relais['narel'] == 'F') { $mode = '24X'; } elseif($mr_relais['narel'] == 'E') { $mode = '24L'; } else { $mode = '24R'; } } $shipping = array( $delivery_address->firstname.' '.$delivery_address->lastname, $mr_relais['colnom'], $mr_relais['colbat'], str_replace(' AVENUE D', ' AV. D', str_replace(' GENERAL LECLERC', ' GAL LECLERC', $mr_relais['colrue'])), $mr_relais['coldit'], $mr_relais['codpos'], $mr_relais['libbp'], empty($delivery_address->phone_mobile)? $delivery_address->phone: $delivery_address->phone_mobile, '', ); $dest_country = (int) Db::getInstance()->getValue(' SELECT `id_country` FROM `'._DB_PREFIX_.'country` WHERE `iso_code` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'" '); } if(mb_strlen($shipping[2]) > 22 && $shipping[3] == '') { $shipping[3] = mb_substr($shipping[2], 22, 22); $shipping[2] = mb_substr($shipping[2], 0, 22); } $format = str_replace( array( '{SHIPPING_NUMBER_C25I}', '{SHIPPING_NUMBER}', '{EXP_COMPANY}', '{EXP_ADDR1}', '{EXP_ADDR2}', '{EXP_POSTCODE}', '{EXP_CITY}', '{DEST_ADDR1}', '{DEST_ADDR2}', '{DEST_ADDR3}', '{DEST_ADDR4}', '{DEST_ADDR5}', '{DEST_POSTCODE}', '{DEST_CITY}', '{DEST_PHONE}', '{DEST_OTHER}', '{SHIPPING_1}', '{SHIPPING_2}', '{SHIPPING_3}', '{SHIPPING_4}', '{SHIPPING_5}', '{SHIPPING_6}', '{SHIPPING_7}', '{SHIPPING_8}', '{EXPEDITION_NUMBER}', '{DATE}', '{AGENCY_CODE}', '{WEIGHT}', '{VOLUME}', '{INSTRUCTIONS}', ), array( $shipping_data['shipping_number_c25i'], $shipping_data['shipping_number_fmt'], $exp_company, $exp_address1, $exp_address2, $exp_postal, $exp_city, $shipping[0], $shipping[1], $shipping[2], $shipping[3], $shipping[4], $shipping[5], $shipping[6], $shipping[7], $shipping[8], $shipping_data['plantri']['cppay'], $shipping_data['plantri']['nogroup'], $shipping_data['plantri']['modexp'], $shipping_data['plantri']['pretri'], // N ... $shipping_data['plantri']['navette'], $shipping_data['plantri']['direction'], // T ... $shipping_data['mode'], $agencies[$shipping_data['plantri']['modexp']], $shipping_data['expedition_number'], date('d/m/Y'), Db::getInstance()->getValue(' SELECT `modexp` FROM `'._DB_PREFIX_.'mondialrelay_tri` WHERE `cppay` = "'.pSQL(Db::getInstance()->getValue(' SELECT `iso_code` FROM `'._DB_PREFIX_.'country` WHERE `id_country` = '.(int) $exp_country.' ')).'" AND `destex` = "'.pSQL($exp_postal).'" '), number_format((float) $shipping_data['weight'], 2, ',', ''), 'NC', '', ), $mondialrelay_formats[$dest_country == 6? 'ES': (in_array($dest_country, array(3, 8, 12))? 'FR': 'EN')] ); return $format; } public function getShippingNumber($id_order) { Db::getInstance()->Execute('SET AUTOCOMMIT = 0'); Db::getInstance()->Execute('START TRANSACTION'); $res = Db::getInstance()->ExecuteS(' SELECT `value` FROM `'._DB_PREFIX_.'logistics_shipping` WHERE `carrier` = "MONDIALRELAY" FOR UPDATE '); $sequence = (int) $res[0]['value'] + 1; // LOOP SHIPPING SEQUENCE if ($sequence < Configuration::get('MONDIALRELAY_SHIPPINGLOW') || $sequence > Configuration::get('MONDIALRELAY_SHIPPINGHIGH')) $sequence = Configuration::get('MONDIALRELAY_SHIPPINGLOW'); // CHECK UNICITY $last_update = Db::getInstance()->getValue('SELECT DATE_ADD(`date_upd`, INTERVAL 1 YEAR) FROM `' . _DB_PREFIX_ . 'mondialrelay_expedition_numbers` WHERE `sequence` = ' . (int) $sequence); if ($last_update && $last_update > date('Y-m-d H:i:s')){ $content = 'Le numéro d\'expédition ' . $sequence . ' a été affecté il y a moins d\'un an.' . "\n" . 'Impossible d\'affecter un nouveau numéro d\'expédition'; mail('marion@antadis.com', '[BBB MONDIAL RELAY] Numéro d\'expédition', $content, 'Content-Type: text/plain; charset="utf-8"'."\r\n".'From: commande@bebeboutik.com'."\r\n".'Reply-To: marion@antadis.com'."\r\n".'Return-Path: marion@antadis.com'."\r\n"); return false; } Db::getInstance()->execute(' INSERT INTO ' . _DB_PREFIX_ . 'mondialrelay_expedition_numbers (`sequence`, `date_upd`) VALUES (' . (int) $sequence . ', "' . pSQL(date('Y-m-d H:i:s')) . '") ON DUPLICATE KEY UPDATE date_upd="' . pSQL(date('Y-m-d H:i:s')) . '"; '); Db::getInstance()->ExecuteS(' UPDATE `'._DB_PREFIX_.'logistics_shipping` SET `value` = "'.(int) $sequence.'" WHERE `carrier` = "MONDIALRELAY" '); Db::getInstance()->Execute('COMMIT'); Db::getInstance()->Execute('SET AUTOCOMMIT = 1'); return $sequence; } public function registerParcel($order, $products, $weight) { global $cookie; $delivery_infos = Db::getInstance()->getRow(' SELECT s.*, m.`dlv_mode` FROM `'._DB_PREFIX_.'mr_selected` s LEFT JOIN `'._DB_PREFIX_.'mr_method` m ON (s.`id_method` = m.`id_mr_method`) WHERE s.`id_order` = '.(int) $order->id.' '); // Hack 5 numbers relay num if (isset($delivery_infos['MR_Selected_Num']) && $delivery_infos['MR_Selected_Num']) { $delivery_infos['MR_Selected_Num'] = substr($delivery_infos['MR_Selected_Num'], -5); } if(!$delivery_infos || in_array($delivery_infos['dlv_mode'], array('LDS', 'LD1', 'HOM'))) { $mode = $delivery_infos? $delivery_infos['dlv_mode']: 'LD1'; $address = Db::getInstance()->getRow(' SELECT a.`postcode`, UPPER(c.`iso_code`) AS `iso_code` FROM `'._DB_PREFIX_.'address` a LEFT JOIN `'._DB_PREFIX_.'country` c ON a.`id_country` = c.`id_country` WHERE a.`id_address` = '.(int) $order->id_address_delivery.' '); $country = $address['iso_code']; $postcode = $address['postcode']; $mode_tri = $mode == 'LD1' ? 'LDR': $mode; $plantri = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_tri` WHERE `destyp` = "CP" AND `destex` = "'.pSQL($postcode).'" AND `cppay` = "'.pSQL($country).'" AND ( `livmod` = "'.pSQL($mode_tri).'" OR `livmod` = "HOM" ) '); if(!$plantri) { $plantri = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_tri` WHERE `destyp` = "CP" AND `destex` = "'.pSQL(substr($postcode, 0, 2)).'" AND `cppay` = "'.pSQL($country).'" AND ( `livmod` = "'.pSQL($mode_tri).'" OR `livmod` = "HOM" ) '); } if($plantri) { $mode = $plantri['livmod']; } } else { $mr_relais = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_relais` WHERE 1 AND `direction` = "'.pSQL($delivery_infos['MR_Selected_Num']).'" AND `prpay` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'" '); $mode = $delivery_infos['dlv_mode']; if($mode == '24R') { if($mr_relais['narel'] == 'F') { $mode = '24X'; } elseif($mr_relais['narel'] == 'E') { $mode = '24L'; } else { $mode = '24R'; } } $country = $delivery_infos['MR_Selected_Pays']; $postcode = $delivery_infos['MR_Selected_CP']; $plantri = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_tri` WHERE `destyp` = "RL" AND `destex` = "'.pSQL($delivery_infos['MR_Selected_Num']).'" AND `cppay` = "'.pSQL($country).'" '); } if(!$plantri) { // TODO: error handling return; } $sequence = $this->getShippingNumber((int) $order->id); if (!$sequence){ return array('
Unicité du numéro d\'expédition non respecté